Esempio n. 1
0
/*-----------------------------------------------------------------------------------*/
static void
apply_tcpipconfig(void)
{
  int file = cfs_open("contiki.cfg", CFS_READ);
  int size = cfs_read(file, uip_buf, 100);
  cfs_close(file);

  nullterminate(ipaddr);
  uiplib_ipaddrconv(ipaddr, (uip_ipaddr_t *)&uip_buf[0]);

  nullterminate(netmask);
  uiplib_ipaddrconv(netmask, (uip_ipaddr_t *)&uip_buf[4]);

  nullterminate(gateway);
  uiplib_ipaddrconv(gateway, (uip_ipaddr_t *)&uip_buf[8]);
  
#if WITH_DNS
  nullterminate(dnsserver);
  uiplib_ipaddrconv(dnsserver, (uip_ipaddr_t *)&uip_buf[12]);
#endif /* WITH_DNS */

  file = cfs_open("contiki.cfg", CFS_WRITE);
  cfs_write(file, uip_buf, size);
  cfs_close(file);
}
Esempio n. 2
0
/*-----------------------------------------------------------------------------------*/
static void
apply_tcpipconfig(void)
{
  uip_ipaddr_t addr;

  nullterminate(ipaddr);
  if(uiplib_ipaddrconv(ipaddr, &addr)) {
    uip_sethostaddr(&addr);
  }
  
  nullterminate(netmask);
  if(uiplib_ipaddrconv(netmask, &addr)) {
    uip_setnetmask(&addr);
  }

  nullterminate(gateway);
  if(uiplib_ipaddrconv(gateway, &addr)) {
    uip_setdraddr(&addr);
  }
  
#if UIP_UDP
  nullterminate(dnsserver);
  if(uiplib_ipaddrconv(dnsserver, &addr)) {
    resolv_conf(&addr);
  }
#endif /* UIP_UDP */
}
Esempio n. 3
0
	void langtrace (bigstring bs) {
		
		nullterminate (bstoken);

		nullterminate (bs);

		fprintf (tracefile, ("'%s' ==> %s" STR_lineterminator), &bstoken[1], &bs[1]);
		
		if (shiftkeydown ())
			waitmouseclick ();
		} /*langtrace*/
Esempio n. 4
0
/*-----------------------------------------------------------------------------------*/
static void
killproc(char *str)
{
  char procnum, j, c;
  char procstr[5];

  nullterminate(str);
  
  procnum = 0;
  
  for(j = 0; j < 4; ++j) {
    c = str[j];
    if(c >= '0' && c <= '9') {
      procnum = procnum * 10 + (str[j] - '0');
    } else {
      break;
    }
  }
  if(procnum != 0) {
    inttostr(procstr, procnum);
    shell_output("Killing process ", procstr);
    ek_post(procnum, EK_EVENT_REQUEST_EXIT, NULL);
  } else {
    shell_output("Invalid process number", "");
  }
  
}
Esempio n. 5
0
/*-----------------------------------------------------------------------------------*/
static char *
copystr(char *dst, char *src, int len)
{
  char *nt = nullterminate(src);
  strncpy(dst, src, len);
  return nt + 1;
}
Esempio n. 6
0
boolean filespectopath (const ptrfilespec fs, bigstring bspath) {
	
	//
	// 2006-09-09 creedon: for Mac, FSRef-ized
	//
	// 2.1a7 dmb: if it's a null filespec, return the empty string
	//
	// 1991-12-17 dmb: don't check for folderness if file doesn't exist-- we dont want to generate any errors here
	//
	// 1991-10-14 dmb: make sure folder paths end in :
	//
	// 1991-06-28 dmb:	when you resolve an alias of a volume, the fsspec has a parent dirid of 1.  we catch this as a
	//				special case here, and return the empty string as the path
	//
	
	#ifdef MACVERSION
	
		boolean flfolder;
		
		setemptystring (bspath);

		if (!directorytopath (fs, bspath))
			return (false);
		
		if (!fs->flags.flvolume) {
			
			bigstring bsfile;
			
			fsnametobigstring (&fs->name, bsfile);
			
			pushstring (bsfile, bspath);
			}
		
		if (fileexists (fs, &flfolder))
			if (flfolder)
				assurelastchariscolon (bspath);
		
		return (true);
		
	#endif

	#ifdef WIN95VERSION
	
		// 5.0d12 dmb: use GetFullPath to clean up 8.3 names
		char * fileptr;
		
		copyptocstring (fsname (fs), bspath);
		
		GetFullPathName (bspath, lenbigstring, bspath, &fileptr);

		convertcstring (bspath);
		
		nullterminate (bspath);

		return (true);
		
	#endif
	
	} // filespectopath
Esempio n. 7
0
/*-----------------------------------------------------------------------------------*/
static void
runfile(char *str)
{
  nullterminate(str);

  if(strlen(str) > 0) {
    /* Call loader function. */
    program_handler_load(str, NULL);
    shell_output("Starting program ", str);  
  } else {
    shell_output("Must supply a program name", "");  
  }
}
Esempio n. 8
0
boolean setfsfile ( ptrfilespec fs, bigstring bsfile ) {

	//
	// 2006-10-18 creedon: for Mac, FSRef-ized
	//
	// 2004-10-26 aradke: Since the getmacfileinfo/foldertest gymnastics do not seem to fit any particular purpose and since
	//			     none of our callers seem to rely it since they usually pass in a file rather than a directory, I
	//			     commented it out.
	// 
	//			     The only time we get called with a directory is apparently by shellopendefaultfile on startup in the
	//			     Carbon/Mach-O build. getapplicationfilespec returns a directory in that case and the code below
	//			     somehow screwed up when called to set the filename to Frontier.root so that it wouldn't be found.
	//
	
	#ifdef MACVERSION
		
		bigstringtofsname (bsfile, &fs->name);
		
		return ( true );
		
	#endif

	#ifdef WIN95VERSION
	
		bigstring bsfolder;
		
		folderfrompath (fsname (fs), bsfolder);
		
		pushstring (bsfile, bsfolder);

		copystring (bsfolder, fsname (fs));

		nullterminate (fsname (fs));

		return (true);
		
	#endif
	
	} // setfsfile
Esempio n. 9
0
boolean pathtofilespec ( bigstring bspath, ptrfilespec fs ) {

    //
    // 2010-01-24 creedon: fix for relative paths not working on mac,
    //                     bsfullpath was ending up with :: in it as well as
    //                     the full path to the application, see initfsdefault
    //                     function
    //
	// 2009-08-30 aradke: refactored mac version to make it easier to understand.
	//			fixed bug where a bspath containing a non-existing volume name was accepted as valid,
	//			e.g. filespec("foobar:"), thus deviating from previous behaviour.
	//
	// 2006-10-16 creedon: for Mac, FSRef-ized
	//
	// 5.0d8 dmb: clear fs first thing
	//
	// 2.1b2 dmb: use new fsdefault for building filespec. note that if bspath
    //            isn't a partial path, the vref and dirid will be ignored.
	//
	// 2.1b2 dmb: added special case for empty string.  also, added drive
    //            number interpretation here.
	//
	// 1993-06-11 dmb: if FSMakeFSSpec returns fnfErr, the spec is cool (but
    //                 file doesn't exist)
	//
	// 1991-012-17 dmb: dont append path to default directory if it's a full
    //                  path
	//
	// 1991-07-05 dmb: use FSMakeFSSpec if it's available.  since it only
    //                 returns noErr if the file exists, and we want to handle
	//                 non-existant files, we don't give up right away.
	//
	
	#ifdef MACVERSION
		FSRef fsr;
		bigstring bspathtmp, bsfullpath, bsfile, bsfolder;
		short ix = 1;
		boolean flvolume = false;
	#endif

	#ifdef WIN95VERSION
		bigstring bsfolder;
	#endif

	clearbytes ( fs, sizeof ( *fs ) );

	if ( isemptystring ( bspath ) )
		return ( true );
		
	#ifdef MACVERSION

		// create cleaned-up full path representation of our input suitable for pathtosref
	
		copystring ( bspath, bspathtmp );

		cleanendoffilename ( bspathtmp );
		
		if ( scanstring ( ':', bspath, &ix ) && ( ix > 1 ) ) {
		
			// contains a colon but doesn't start with one, so it must be a full path
			
			if ( ix == stringlength ( bspath ) )	// the colon we found is the last char, so bspath is a volume name
				flvolume = true;
                
			copystring ( bspathtmp, bsfullpath );
			}
            
		else {
		
			// it's a partial path, prefix with default directory (see initfsdefault)
		
			if ( ! filespectopath ( &fsdefault, bsfullpath ) )	// get path of default directory
				return ( false );
                
           // delete first path separator if partial path begins with one because bsfullpath always ends with one
           
			if ( bspathtmp [ 1 ] == chpathseparator )
				deletefirstchar ( bspathtmp );
                
			pushstring ( bspathtmp, bsfullpath );	// append partial path
			}
            
		// now see if the full path resolves 
			
		if ( pathtofsref ( bsfullpath, &fsr ) == noErr ) {

			return ( macmakefilespec ( &fsr, fs ) == noErr );
			}
			
		// full path did not resolve but we actually only require the parent folder to exist
		
		if ( ! flvolume ) {		// volumes don't have a parent folder
		
			filefrompath ( bsfullpath, bsfile );
			
			folderfrompath ( bsfullpath, bsfolder );

			if ( pathtofsref ( bsfolder, &fsr ) == noErr ) {
				
				clearfilespec ( fs );
				
				fs->ref = fsr;
				
				bigstringtofsname ( bsfile, &fs->name );
			
				return ( true );
				}
			}
		
		return ( false );
		
	#endif

	#ifdef WIN95VERSION
	
		copystring (bspath, fsname (fs));

		folderfrompath (bspath, bsfolder);

		if ((isemptystring (bsfolder)) && (! fileisvolume(fs))) {

			filegetdefaultpath (fs);

			pushstring (bspath, fsname (fs));
			}
		
		nullterminate (fsname (fs));
		
		return (true);

	#endif

	} // pathtofilespec
Esempio n. 10
0
static boolean sysfunctionvalue (short token, hdltreenode hparam1, tyvaluerecord *vreturned, bigstring bserror) {
	
	//
	// 2006-06-28 creedon: for Mac, FSRef-ized
	//
	// 5.0b16 dmb: undo that change. it affect performance adversely if many threads do it.
	//
	// 5.0b12 dmb: in systemtaskfunc, set flresting to false to make sure we don't slow down too much
	//
	// 1/18/93 dmb: in systemtaskfunc, don't call processyield directly; use langbackgroundtask
	//
	// 8/11/92 dmb: make apprunningfunc accept a string or an ostype
	//
	// 5/20/92 dmb: do processyield directly on systemtaskfunc
	//
	// 2/12/92 dmb: do partialeventloop on systemtask & bringapptofrontfunc
	//
	
	register tyvaluerecord *v = vreturned;
	
	setbooleanvalue (false, v); /*assume the worst*/
	
	switch (token) { /*these verbs don't need any special globals pushed*/
		
		case systemversionfunc: {
			bigstring bs;
			
			getsystemversionstring (bs, nil);
			
			if (!langcheckparamcount (hparam1, 0))
				return (false);
						
			return (setstringvalue (bs, v));
			}
		
		case systemtaskfunc:
			if (!langcheckparamcount (hparam1, 0)) /*shouldn't have any parameters*/
				return (false);
			
			shellsysverbwaitroutine ();
			
			/*
			if (!processyield ())
				return (false);
			*/
			
			if (!langbackgroundtask (true))
				return (false);
			
			(*v).data.flvalue = true;
			
			return (true);
		
		case browsenetworkfunc:
		
			#ifdef MACVERSION
			
				return (langipcbrowsenetwork (hparam1, v));
				
			#endif
			
			#ifdef WIN95VERSION
			
				#pragma message ("WIN95: browsenetworkfunc - not yet implemented!")
			
				break;
				
			#endif

		case apprunningfunc: {
			OSType appid;
			bigstring bsapp;
			tyvaluerecord val;
			
			flnextparamislast = true;
			
			/*
			if (!getostypevalue (hparam1, 1, &appid))
				return (false);
			
			(*v).data.flvalue = findrunningapplication (&appid, nil);
			*/
			
			if (!getparamvalue (hparam1, 1, &val))
				return (false);
			
			if (val.valuetype == ostypevaluetype) {
				
				setemptystring (bsapp);
				
				appid = val.data.ostypevalue;
				}
			else {
				if (!coercetostring (&val))
					return (false);
				
				pullstringvalue (&val, bsapp);
				
				if (!stringtoostype (bsapp, &appid))
					appid = 0;
				}
			
			(*v).data.flvalue = findrunningapplication (&appid, bsapp, nil);
			
			return (true);
			}
		
		case frontappfunc: {
			bigstring bs;
			
			if (!langcheckparamcount (hparam1, 0))
				return (false);
			
			if (!getfrontapplication (bs, false))
				return (false);
			
			return (setstringvalue (bs, v));
			}
		
		case bringapptofrontfunc: {
			bigstring bs;
			
			flnextparamislast = true;
			
			if (!getstringvalue (hparam1, 1, bs))
				return (false);
			
			(*v).data.flvalue = activateapplication (bs);
			
			return (true);
			}
		
		case countappsfunc:
			if (!langcheckparamcount (hparam1, 0))
				return (false);
			
			return (setlongvalue (countapplications (), v));
		
		case getnthappfunc: {
			short n;
			bigstring bs;
			
			if (!getintvalue (hparam1, 1, &n))
				return (false);
			
			if (!getnthapplication (n, bs))
				setemptystring (bs);
			
			return (setstringvalue (bs, v));
			}
		
		case getapppathfunc: {
			bigstring bs;
			tyfilespec fs;
			
			flnextparamislast = true;
			
			if ( ! getstringvalue ( hparam1, 1, bs ) )
				return ( false );
			
			if ( ! getapplicationfilespec ( bs, &fs ) ) // 2006-02-17 aradke: initializes fs even if it fails
				setemptystring (bs);
				
			return ( setfilespecvalue ( &fs, v ) );
			}
		
		case memavailfunc:
			{
			unsigned long memavail;

			#ifdef WIN95VERSION
				MEMORYSTATUS meminfo;

				meminfo.dwLength = sizeof (MEMORYSTATUS);

				GlobalMemoryStatus (&meminfo);

				memavail = meminfo.dwAvailVirtual;
			#endif

			#ifdef MACVERSION
				memavail = TempFreeMem();
			#endif
			
			if (!langcheckparamcount (hparam1, 0)) /*shouldn't have any parameters*/
				return (false);
			
			return (setlongvalue (memavail, v));
			}
		
		case machinefunc:
			
			#ifdef MACVERSION
				//Code change by Timothy Paustian Friday, June 16, 2000 3:13:09 PM
				//Changed to Opaque call for Carbon
				//Carbon only runs on PPC
				#if TARGET_API_MAC_CARBON
				return (setstringvalue (machinePPC, v));
				#else
				#if GENERATINGPOWERPC
				return (setstringvalue (machinePPC, v));
				#endif
				#if GENERATING68K
				return (setstringvalue (machine68K, v));
				#endif
				#endif

				
			#endif
			
			#ifdef WIN95VERSION
				return (setstringvalue (machinex86, v));
			#endif

			break;

		case osfunc:
			return (sysos (v));
			break;

		#ifdef WIN95VERSION
			case getenvironmentvariablefunc: {
				bigstring bsenvname;
				bigstring buf;
				DWORD res;
				
				flnextparamislast = true;
				
				if (!getstringvalue (hparam1, 1, bsenvname))
					return (false);

				nullterminate(bsenvname);

				res = GetEnvironmentVariable (stringbaseaddress(bsenvname), stringbaseaddress(buf), sizeof(buf)-2);

				if (res > sizeof(buf) - 2) {
					return (setbooleanvalue (false, v));		//safety valve
					}

				setstringlength (buf, res);

				return (setstringvalue (buf, v));
				}
				break;

			case setenvironmentvariablefunc: {
				bigstring bsenvname;
				bigstring bsenvval;
				bigstring bserror, bserror2;
				boolean res;
				
				if (!getstringvalue (hparam1, 1, bsenvname))
					return (false);

				flnextparamislast = true;
				
				if (!getstringvalue (hparam1, 2, bsenvval))
					return (false);

				nullterminate(bsenvname);
				nullterminate(bsenvval);

				res = SetEnvironmentVariable (stringbaseaddress(bsenvname), stringbaseaddress(bsenvval));

				if (res) {
					return (setbooleanvalue (true, v));	
					}

				getsystemerrorstring (GetLastError(), bserror);

				nullterminate(bserror);

				wsprintf (bserror2, "Can't set environment variable \"%s\" to \"%s\" because %s", stringbaseaddress (bsenvname), stringbaseaddress (bsenvval), stringbaseaddress (bserror));

				setstringlength (bserror2, strlen(stringbaseaddress(bserror2)));

				shellerrormessage (bserror2);

				return (setbooleanvalue (false, v));	
				}
				break;
		#endif
		
		#if TARGET_API_MAC_CARBON == 1
		
			case unixshellcommandfunc: { /*7.0b51 PBS: call shell on OS X*/
			
				Handle hcommand, hreturn;
				
				flnextparamislast = true;
				
				if (!getexempttextvalue (hparam1, 1, &hcommand))
					return (false);
				
				newemptyhandle (&hreturn);
										
				if (!unixshellcall (hcommand, hreturn)) {
				
					disposehandle (hreturn);
					
					disposehandle (hcommand);
					
					return (false);
					} /*if*/
				
				disposehandle (hcommand);
					
				return (setheapvalue (hreturn, stringvaluetype, v));
				}
		
		#endif 
		
		#ifdef WIN95VERSION

			case winshellcommandfunc: {
				Handle hcommand;
				Handle houttext = nil;
				Handle herrtext = nil;
				long exitcode = 0;
				tyaddress adrexitcode, adrstderr;
				short ctconsumed = 1;
				short ctpositional = 1;
				boolean flneedexitcode, flneedstderr;
				tyvaluerecord val;
				
				if (!getexempttextvalue (hparam1, 1, &hcommand))
					return (false);
				
				if (!getoptionaladdressparam (hparam1, &ctconsumed, &ctpositional, "\x0b" "adrExitCode", &adrexitcode.ht, adrexitcode.bs))
					return (false);
				
				flnextparamislast = true;
				
				if (!getoptionaladdressparam (hparam1, &ctconsumed, &ctpositional, "\x0b" "adrStdErr", &adrstderr.ht, adrstderr.bs))
					return (false);
				
				flneedexitcode = (adrexitcode.ht != nil) || !isemptystring (adrexitcode.bs);
				
				flneedstderr = (adrstderr.ht != nil) || !isemptystring (adrstderr.bs);

				newemptyhandle (&houttext);

				if (flneedstderr)
					newemptyhandle (&herrtext);
										
				if (!winshellcall (hcommand, houttext, herrtext,
										(flneedexitcode ? &exitcode : nil))) {
				
					disposehandle (houttext);
					
					disposehandle (herrtext);
					
					disposehandle (hcommand);
					
					return (false);
					} /*if*/
				
				disposehandle (hcommand);
				
				if (flneedexitcode) {

					setlongvalue (exitcode, &val);
					
					if (!langsetsymboltableval (adrexitcode.ht, adrexitcode.bs, val))
						return (false);
					}
					
				if (flneedstderr) {

					setheapvalue (herrtext, stringvaluetype, &val);
					
					if (!langsetsymboltableval (adrstderr.ht, adrstderr.bs, val))
						return (false);
					
					exemptfromtmpstack (&val);
					}
					
				return (setheapvalue (houttext, stringvaluetype, v));
				}

		#endif //WIN95VERSION
		
		default:
			break;
		}

	getstringlist (langerrorlist, unimplementedverberror, bserror);

	return (false);
	} /*sysfunctionvalue*/