Example #1
0
/* Execute external script/program */
int
notify_exec(char *cmd)
{
	pid_t pid;
	int ret;

	pid = fork();

	/* In case of fork is error. */
	if (pid < 0) {
		log_message(LOG_INFO, "Failed fork process");
		return -1;
	}

	/* In case of this is parent process */
	if (pid)
		return 0;

	signal_handler_destroy();
	closeall(0);

	open("/dev/null", O_RDWR);
	ret = dup(0);
	ret = dup(0);

	system_call(cmd);

	exit(0);
}
Example #2
0
File: idt.c Project: BFridge/OS
/**
* This function handles most interrupts by finding out the interrupt #
* and calling the appropriate handler functions
*
* @param ptr_to_stack Pointer to top of stack
*/
void main_interrupt_handler(uint ptr_to_stack)
{
    struct handler_stack_frame* frame = (struct handler_stack_frame*)&ptr_to_stack;

    if (frame->interrupt_number)
    {
        klprintf(15, "Handling interrupt #%d, ticks=%d", frame->interrupt_number, get_system_ticks());

        switch(frame->interrupt_number)
        {
        
        case DIVIDE_ERROR: case DEBUG_EXCEPTION: case NMI_HARDWARE: case DEBUG_BREAKPOINT:
        case INSTRUCTION_OVERFLOW: case INSTRUCTION_OVERRANGE: case INVALID_OPCODE: case NO_COPROCESSOR:
        case DOUBLE_FAULT: case COPROCESSOR_SEG_OVERRUN: case INVALID_TSS: case SEGMENT_NOT_PRESENT:
        case STACK_FAULT: case GENERAL_PROTECTION_FAULT: case PAGE_FAULT: case RESERVED15: case COPROCESSOR_ERROR:
        case ALIGNMENT_CHECK: case MACHINE_CHECK:
            kernel_error(frame->interrupt_number, frame->stck_frame.eip, frame->stck_frame.esp,
                        frame->eax, frame->ebx, frame->ecx, frame->edx, frame->edi, frame->esi);
            break;
        case TIMER_IRQ:  
            timer_interrupt_handler();
            break;
        case SYSTEM_CALL:
            system_call( frame );
            break;
        }
    }
}
Example #3
0
int main (int argc , char* argv[], char* envp[]) {

    int fd, nread;
    char buf[BUF_SIZE];
    struct linux_dirent *d;
    int bpos;
    char d_type;
    int flag = 0;
                    
    system_call(SYS_WRITE,STDOUT,"Flame2 Strikes Again! \n",23);

    if (argc == 2) 
        flag =1 ;
    fd = system_call(SYS_OPEN,".",0);
    if (fd <0)
        system_call(SYS_EXIT,0x55);

    for ( ; ; ) {

        nread = system_call(SYS_GETDENTS, fd, buf, BUF_SIZE);
        if (nread < 0)
            system_call(SYS_EXIT,0x55);

        if (nread == 0)
            break;

        for (bpos = 0; bpos < nread;) {

            d = (struct linux_dirent *) (buf + bpos);


            /* TODO - need to fix */
                if (strncmp(d->d_name, argv[2],strlen(argv[2])) != 0){

                    system_call(SYS_WRITE,STDOUT,d->d_name,strlen(d->d_name));
                    system_call(SYS_WRITE,STDOUT,"\n",1);
                    bpos += d->d_reclen;
                } 
                else {

                    system_call(SYS_WRITE,STDOUT,d->d_name,strlen(d->d_name));
                    system_call(SYS_WRITE,STDOUT,"\n",1);
                    bpos += d->d_reclen;

                }
            

            }

        }
    }
int cAppliMMTestOrient::Exec()
{
   if (mMMV) return EXIT_SUCCESS;
   int aRes = system_call(mCom.c_str());

   BanniereMM3D();

   return aRes;
}
Example #5
0
DLLEXPORT y_handle y_process_create(xstring name, char *cmdline)
{
	struct sysreq_process_create req;

	req.base.req_id = SYS_REQ_KERNEL_PROCESS_CREATE;
	req.name		= name;
	req.cmdline		= cmdline;

	return (y_handle)system_call(&req);
}
Example #6
0
static ke_handle create_thread(void *entry, void * arg, bool run)
{
	struct sysreq_thread_create req;
	req.base.req_id = SYS_REQ_KERNEL_THREAD_CREATE;
	req.wrapper		= thread_wrap;
	req.entry		= entry;
	req.para		= (unsigned long)arg;
	req.run			= run;
	return (ke_handle)system_call(&req);	
}
Example #7
0
int MakeGrid_main(int argc,char ** argv)
{
    MMD_InitArgcArgv(argc,argv);

    NoInit = "XXXXXXXXXX";

    MemoArg(argc,argv);
    std::string  aDir,aPat,aFullDir;

    std::string AeroIn;
    std::string AeroOut;
    //std::vector<std::string> ImPl;

    ElInitArgMain
    (
    argc,argv,
    LArgMain()  << EAMC(aFullDir, "Full Directory (Dir+Pattern)", eSAM_IsPatFile)
                    << EAMC(AeroIn, "Input Orientation", eSAM_IsExistDirOri),
    LArgMain()
                    << EAM(AeroOut,"Out",true)
    );

    if (!MMVisualMode)
    {
        if (AeroOut=="")
           AeroOut = "Grid-"+AeroIn;

        #if (ELISE_windows)
            replace( aFullDir.begin(), aFullDir.end(), '\\', '/' );
        #endif
        SplitDirAndFile(aDir,aPat,aFullDir);


    #if (ELISE_windows)
        std::string aCom =     MMDir() + std::string("bin\\Apero ")
    #else
        std::string aCom =     MMDir() + std::string("bin/Apero ")
    #endif
                           +  MMDir() + std::string("include/XML_MicMac/AperoGrid.xml ")
                           + std::string(" DirectoryChantier=") +aDir +  std::string(" ")
                           + std::string(" +PatternAllIm=") + QUOTE(aPat) + std::string(" ")
                           + std::string(" +AeroOut=-") + AeroOut
                           + std::string(" +AeroIn=-") + AeroIn
                        ;

       std::cout << "Com = " << aCom << "\n";
       int aRes = system_call(aCom.c_str());


       return aRes;
    }
    else
        return EXIT_SUCCESS;
}
Example #8
0
void debugging(char* exp_, char* msg, int toDebag,int mode){

  if(toDebag){
    
    if(mode==STDIN){
       
        if(*msg=='\n')
            system_call(SYS_WRITE , STDERR , "\n" , 1);
         else
            system_call(SYS_WRITE , STDERR , msg , 1);
    }
    else{

      system_call(SYS_WRITE,STDERR, exp_,strlen(exp_));
    system_call(SYS_WRITE,STDERR, ": ",2);
    system_call(SYS_WRITE,STDERR, msg,strlen(msg));
     system_call(SYS_WRITE,STDERR, "\n",1)''
  
    }
}}
Example #9
0
int ChgSysCo_main(int argc,char ** argv)
{
    MMD_InitArgcArgv(argc,argv);

    std::string aFullDir= "";
    std::string AeroIn= "";
    std::string aStrChSys="";
    std::string AeroOut="";
    bool        ForceRot = false;


    ElInitArgMain
    (
        argc,argv,
        LArgMain()  << EAMC(aFullDir,"Full Directory (Dir+Pattern)", eSAM_IsPatFile)
                    << EAMC(AeroIn,"Input Orientation", eSAM_IsExistDirOri)
                    << EAMC(aStrChSys,"Change coordinate file", eSAM_IsExistFile)
                    << EAMC(AeroOut,"Output Orientation", eSAM_IsOutputDirOri),
        LArgMain()  << EAM(ForceRot,"FR",true,"Force orientation matrix to be pure rotation (Def = true)", eSAM_IsBool)
    );

    if (!MMVisualMode)
    {
        std::string aDir,aPat;
    #if (ELISE_windows)
        replace( aFullDir.begin(), aFullDir.end(), '\\', '/' );
    #endif
        SplitDirAndFile(aDir,aPat,aFullDir);
        StdCorrecNameOrient(AeroIn,aDir);

        std::cout << "DPPPP= " << aDir << " " << aPat << "\n";



        std::string aCom =       MM3dBinFile( "Apero" )
                              +  XML_MM_File("Apero-ChCo.xml")
                              +  std::string(" DirectoryChantier=") + aDir + " "
                              +  std::string(" +SetIm=") + aPat + " "
                              +  std::string(" +AeroIn=-") + AeroIn + " "
                              +  std::string(" +AeroOut=-") + AeroOut + " "
                              +  std::string(" +ChC=") + aStrChSys + " "
                              +  std::string(" +ChCFR=") + ToString(ForceRot)
                           ;


       std::cout << "COM = " << aCom << "\n";
       int aRes = system_call(aCom.c_str());
       return aRes;
    }
    else return EXIT_SUCCESS;
}
Example #10
0
int MMAllAuto_main(int argc,char ** argv)
{
    MMD_InitArgcArgv(argc,argv);

    std::string  aDir,aPat,aFullDir;
    std::string  AeroIn;
    int          aZoomF = 2;


    ElInitArgMain
    (
    argc,argv,
    LArgMain()  << EAMC(aFullDir,"Dir + Pattern", eSAM_IsPatFile)
                    << EAMC(AeroIn,"Orientation", eSAM_IsExistDirOri),
    LArgMain()
                    << EAM(aZoomF,"ZoomF",true,"Zoom Final, def=2",eSAM_IsPowerOf2)
    );

#if (ELISE_windows)
    replace( aFullDir.begin(), aFullDir.end(), '\\', '/' );
#endif
    SplitDirAndFile(aDir,aPat,aFullDir);
    StdCorrecNameOrient(AeroIn,aDir);

    cInterfChantierNameManipulateur * aICNM =  cInterfChantierNameManipulateur::BasicAlloc(aDir);

    // Genere les pyramides pour que le paral ne s'ecrase pas les 1 les autres

    const cInterfChantierNameManipulateur::tSet * aSetIm = aICNM->Get(aPat);


    for (int aKIm=0 ; aKIm<int(aSetIm->size()) ; aKIm++)
    {
        std::string aCom =   MM3dBinFile("MICMAC")
                              + XML_MM_File("MM-AllAuto.xml")
                              + std::string(" WorkDir=") +aDir +  std::string(" ")
                              + std::string(" +Im1=") + QUOTE((*aSetIm)[aKIm]) + std::string(" ")
                              + std::string(" +Ori=-") + AeroIn
                              + std::string(" +ZoomF=") + ToString(aZoomF)
                    ;



        system_call(aCom.c_str());
  }

 // int aRes = system_call(aCom.c_str());


   return 0;
}
Example #11
0
static asmregparm void thread_wrap(void *(PTCDECL *start) (void *), void *arg)
{
	struct sysreq_process_startup req;

// 	printf("User level thread wrapper, start is %x, arg %x\n", start, arg);
	start(arg);

	/* Kill current thread, like the ld.sys */
	req.base.req_id		= SYS_REQ_KERNEL_PROCESS_STARTUP;
	req.func			= SYSREQ_PROCESS_STARTUP_FUNC_END;
	system_call(&req);

	/* Will not reach here */
}
Example #12
0
File: editmsg.c Project: wfp5p/elm
int edit_message(const char *filename, SEND_HEADER *shdr,
		 const char *sel_editor)
{
    /* Return 0 if successful, -1 on error. */

    char buffer[SLEN];
    int rc, return_value = 0, err;

    /* pick default editor on NULL */
    if (sel_editor == NULL)
	sel_editor = (IS_BUILTIN(editor) ? alternative_editor : editor);

    /* handle request for the builtin editor */
    if (IS_BUILTIN(sel_editor))
	return builtin_editor(filename, shdr);

    /* we will be running an external editor */
    PutLine(LINES, 0, catgets(elm_msg_cat, ElmSet, ElmInvokeEditor,
	    "Invoking editor..."));

    if (strstr(sel_editor, "%s") != NULL)
	sprintf(buffer, sel_editor, filename);
    else
	sprintf(buffer, "%s %s", sel_editor, filename);

    chown(filename, userid, groupid);

    if ((rc = system_call(buffer, SY_COOKED|SY_ENAB_SIGHUP|SY_DUMPSTATE)) < 0) {
	err = errno;
	dprint(1, (debugfile,
	    "System call failed with status %d (edit_message)\n", rc));
	dprint(1, (debugfile, "** %s **\n", strerror(err)));
	ClearLine(LINES-1);
	show_error(catgets(elm_msg_cat, ElmSet, ElmCantInvokeEditor,
	    "Can't invoke editor '%s' for composition."), sel_editor);
	if (sleepmsg > 0)
	    sleep(sleepmsg);
	return_value = -1;
    }

    /* Flush input buffer.  This is especially important under X,
    * where accidental keystrokes in the elm window could make
    * things messy.
    */
    if (edit_flush)
	FlushInput();

    return return_value;
}
Example #13
0
void * sys_vmalloc(xstring name, void *addr, size_t len, int prot)
{
	struct sysreq_memory_virtual_alloc req;
	
	req.base_address = (unsigned long)addr;
	req.mem_prot	 = prot;
	req.size		 = len;
	req.name		 = name;

	req.base.req_id = SYS_REQ_KERNEL_VIRTUAL_ALLOC;
	
	if (system_call(&req) == KE_INVALID_HANDLE)
	{
		return NULL;
	}

	return (void *)req.out_base;
}
Example #14
0
int Drunk_main(int argc,char ** argv)
{

    //Testing the existence of argument (if not, print help file)
    if(!MMVisualMode && argc==1)
    {
        argv[1]=(char*)"";//Compulsory to call MMD_InitArgcArgv
        MMD_InitArgcArgv(argc,argv);
        string cmdhelp;
        cmdhelp=MMDir()+"bin/Drunk -help";
        system_call(cmdhelp.c_str());
    }
    else
    {
        MMD_InitArgcArgv(argc,argv);

        string aFullPattern,aOri;
        string DirOut="DRUNK/";
        bool Talk=true;

        //Reading the arguments
        ElInitArgMain
        (
            argc,argv,
            LArgMain()  << EAMC(aFullPattern,"Images Pattern", eSAM_IsPatFile)
                        << EAMC(aOri,"Orientation name", eSAM_IsExistDirOri),
            LArgMain()  << EAM(DirOut,"Out",true,"Output folder (end with /) and/or prefix (end with another char)")
                        << EAM(Talk,"Talk",true,"Turn on-off commentaries")
                    );

        //Processing the files
		string aPattern, aDir;
		SplitDirAndFile(aDir, aPattern, aFullPattern);
		StdCorrecNameOrient(aOri, aDir);
        Drunk(aPattern,aOri,DirOut,Talk);
    }

    return EXIT_SUCCESS;
}
Example #15
0
int vicod_main(int argc,char ** argv)
{
    string Name;
    std::string anEdit = "vi";

    ElInitArgMain
    (
        argc,argv,
        LArgMain() 	<< EAM(Name) ,
        LArgMain() 	 << EAM(anEdit,"editor",true)
    );	

    string aNewName;
    decoder_force(Name.c_str(),aNewName);

    std::string  aCom = anEdit + " " + aNewName;
    system_call(aCom.c_str());

    coder_force(aNewName.c_str());

    return 0;
}
FB::variant BracExtenssionProviderAPI::systemCall(const FB::variant& msg) {
	std::string cmd = msg.convert_cast<std::string>();
	m_syscall_commands.push_back(cmd);
#if defined _WIN32
	STARTUPINFO info = {sizeof(info)};
	info.dwFlags = STARTF_USESHOWWINDOW;
	info.wShowWindow = SW_HIDE;
	PROCESS_INFORMATION processInfo;
	std::wstring wcmd = s2ws("cmd.exe /c \"" + cmd + "\"");
	LPWSTR lpwstr_cmd = &wcmd[0];
	std::string res = "";
	if (CreateProcess(NULL, lpwstr_cmd , NULL, NULL, TRUE, 0, NULL, NULL, &info, &processInfo))
	{
		res = "True";
		::WaitForSingleObject(processInfo.hProcess, INFINITE);
		CloseHandle(processInfo.hProcess);
		CloseHandle(processInfo.hThread);
	}
#elif defined __APPLE__
	std::string res = system_call(cmd);
#endif
	m_syscall_results.push_back(res);
	return res;
}
Example #17
0
PUBLIC int fileRead(int fd, char* buf, int size)
{
	disp_color_str("api file read@@@@@", 0x3F);
	return system_call(NR_SYS_FILE_READ, fd, (u32)buf, size, 0, 0);
}
int SBGlobBascule_main(int argc,char ** argv)
{
    NoInit = "NoP1P2";
    aNoPt = Pt2dr(123456,-8765432);

    // MemoArg(argc,argv);
    MMD_InitArgcArgv(argc,argv);
    std::string  aDir,aPat,aFullDir;
    bool ExpTxt=false;
    std::string AeroIn;
    std::string AeroOut;
    std::string PostPlan="_Masq";
    std::string FileMesures ;
    std::string TargetRep = "ki" ;
    bool  CPI = false;


    double DistFE = 0;
    //Pt3dr  Normal;
    //Pt3dr  SNormal;

    ElInitArgMain
    (
    argc,argv,
    LArgMain()  << EAMC(aFullDir,"Full name (Dir+Pat)", eSAM_IsPatFile )
                    << EAMC(AeroIn,"Orientation in", eSAM_IsExistDirOri)
                    << EAMC(FileMesures,"Images measures xml file", eSAM_IsExistFile)
                    << EAMC(AeroOut,"Out : orientation ", eSAM_IsOutputDirOri),
    LArgMain()
                    << EAM(ExpTxt,"ExpTxt",true)
                    << EAM(PostPlan,"PostPlan",true)
                    << EAM(DistFE,"DistFS",true,"Distance between Ech1 and Ech2 to fix scale (if not given no scaling)")
                    << EAM(TargetRep,"Rep",true,"Target coordinate system (Def = ki, ie normal is vertical)")
                    << EAM(CPI,"CPI",true,"Calibration Per Image (Def=false)")

    );

    if (!MMVisualMode)
    {
#if (ELISE_windows)
        replace( aFullDir.begin(), aFullDir.end(), '\\', '/' );
#endif
        SplitDirAndFile(aDir,aPat,aFullDir);
        if (EAMIsInit(&PostPlan))
        {
            CorrecNameMasq(aDir,aPat,PostPlan);
        }

        StdCorrecNameOrient(AeroIn,aDir);


        MMD_InitArgcArgv(argc,argv);

        std::string aCom =   MM3dBinFile( "Apero" )
                + MMDir() + std::string("include/XML_MicMac/Apero-SB-Bascule.xml ")
                + std::string(" DirectoryChantier=") +aDir +  std::string(" ")
                + std::string(" +PatternAllIm=") + QUOTE(aPat) + std::string(" ")
                + std::string(" +AeroOut=-") +  AeroOut
                + std::string(" +Ext=") + (ExpTxt?"txt":"dat")
                + std::string(" +AeroIn=-") + AeroIn
                + std::string(" +PostMasq=") + PostPlan
                + std::string(" +DistFE=") + ToString(DistFE)
                + std::string(" +RepNL=") + TargetRep
                + std::string(" +FileMesures=") + FileMesures
                + std::string(" +CPI=") + ToString(CPI)
                ;



        std::cout << "Com = " << aCom << "\n";
        int aRes = system_call(aCom.c_str());


        return aRes;
    }
    else
    {
        return EXIT_SUCCESS;
    }
}
Example #19
0
PUBLIC void fileClose(int fd)
{
	disp_color_str("api file close@@@@@", 0x3F);
	system_call(NR_SYS_FILE_CLOSE, (u32)fd, 0, 0, 0, 0);
}
Example #20
0
PUBLIC int createProcess(const char* processName)
{
	disp_color_str("api create process@@@@", 0x3F);
	return (int)system_call(NR_SYS_CREATE_PROCESS, (u32)processName, 0, 0, 0, 0);
}
Example #21
0
static word fetch_file(void)
{
   // Returns 0=Success with relevant file open on fp_result
   // Or !0 = failure and file is closed.
   // DANGER: In failure case, fp_result is INVALID and may not be null.
   char zs[256], filepathz[256], filepath[256], url[256];
   time_t now, when;
   struct tm * broken;
   static char * weekdays[] = { "sun", "mon", "tue", "wed", "thu", "fri", "sat" };

   stats[Fetches]++;

   now = time(NULL);
   if(!opt_filename)
   {
      static CURL * curlh;
      struct curl_slist * slist;

      if(!(curlh = curl_easy_init())) 
      {
         _log(CRITICAL, "fetch_file():  Failed to obtain libcurl easy handle.");
         return 1;
      }
      curl_easy_setopt(curlh, CURLOPT_WRITEFUNCTION, cif_write_data);

      slist = NULL;
      slist = curl_slist_append(slist, "Cache-Control: no-cache");
      if(!slist)
      {
         _log(MAJOR,"fetch_file():  Failed to create slist.");
         return 1;
      }

      // Build URL
      when = now - 24*60*60;
      broken = localtime(&when); // Note broken contains "yesterday"
      if(opt_url)
      {
         strcpy(url, opt_url);
      }
      else
      {
         if(fetch_all)
         {
            sprintf(url, "https://datafeeds.networkrail.co.uk/ntrod/CifFileAuthenticate?type=CIF_ALL_FULL_DAILY&day=toc-full");
         }
         else
         {
            sprintf(url, "https://datafeeds.networkrail.co.uk/ntrod/CifFileAuthenticate?type=CIF_ALL_UPDATE_DAILY&day=toc-update-%s", weekdays[broken->tm_wday]);
         }
      }
      sprintf(zs, "Fetching \"%s\".", url);
      _log(GENERAL, zs);

      if(opt_url || debug)
      {
         sprintf(filepathz, "/tmp/tscdb-cif-fetch-%ld.gz", now);
         sprintf(filepath,  "/tmp/tscdb-cif-fetch-%ld",    now);
      }
      else if(fetch_all)
      {
         sprintf(filepathz, "/tmp/tscdb-cif-all-%02d-%02d-%02d-%s.gz", broken->tm_year%100, broken->tm_mon + 1, broken->tm_mday, weekdays[broken->tm_wday]);
         sprintf(filepath,  "/tmp/tscdb-cif-all-%02d-%02d-%02d-%s",    broken->tm_year%100, broken->tm_mon + 1, broken->tm_mday, weekdays[broken->tm_wday]);
      }
      else
      {
         sprintf(filepathz, "/tmp/tscdb-cif-%02d-%02d-%02d-%s.gz", broken->tm_year%100, broken->tm_mon + 1, broken->tm_mday, weekdays[broken->tm_wday]);
         sprintf(filepath,  "/tmp/tscdb-cif-%02d-%02d-%02d-%s",    broken->tm_year%100, broken->tm_mon + 1, broken->tm_mday, weekdays[broken->tm_wday]);
      }

      if(!(fp_result = fopen(filepathz, "w")))
      {
         sprintf(zs, "Failed to open \"%s\" for writing.", filepathz);
         _log(MAJOR, zs);
         return 1;
      }

      curl_easy_setopt(curlh, CURLOPT_HTTPHEADER, slist);

      // Set timeouts
      curl_easy_setopt(curlh, CURLOPT_NOSIGNAL,              1L);
      curl_easy_setopt(curlh, CURLOPT_FTP_RESPONSE_TIMEOUT, 128L);
      curl_easy_setopt(curlh, CURLOPT_TIMEOUT,              128L);
      curl_easy_setopt(curlh, CURLOPT_CONNECTTIMEOUT,       128L);

      // Debugging prints.
      // curl_easy_setopt(curlh, CURLOPT_VERBOSE,               1L);

      // URL and login
      curl_easy_setopt(curlh, CURLOPT_URL,     url);
      sprintf(zs, "%s:%s", conf[conf_nr_user], conf[conf_nr_password]);
      curl_easy_setopt(curlh, CURLOPT_USERPWD, zs);
      curl_easy_setopt(curlh, CURLOPT_FOLLOWLOCATION,        1L);  // On receiving a 3xx response, follow the redirect.
      total_bytes = 0;

      CURLcode result;
      if((result = curl_easy_perform(curlh)))
      {
         _log(MAJOR, "fetch_file(): curl_easy_perform() returned error %d: %s.", result, curl_easy_strerror(result));
         if(opt_insecure && (result == 51 || result == 60))
         {
            _log(MAJOR, "Retrying download in insecure mode.");
            // SSH failure, retry without
            curl_easy_setopt(curlh, CURLOPT_SSL_VERIFYPEER, 0L);
            curl_easy_setopt(curlh, CURLOPT_SSL_VERIFYHOST, 0L);
            used_insecure = true;
            if((result = curl_easy_perform(curlh)))
            {
               _log(MAJOR, "fetch_file(): In insecure mode curl_easy_perform() returned error %d: %s.", result, curl_easy_strerror(result));
               if(fp_result) fclose(fp_result);
               fp_result = NULL;
               return 1;
            }
         }
         else
         {
            if(fp_result) fclose(fp_result);
            fp_result = NULL;
            return 1;
         }
      }
      char * actual_url;
      if(!curl_easy_getinfo(curlh, CURLINFO_EFFECTIVE_URL, &actual_url) && actual_url)
      {
         _log(GENERAL, "Download was redirected to \"%s\".", actual_url);
      }
   
      if(fp_result) fclose(fp_result);
      fp_result = NULL;
      if(curlh) curl_easy_cleanup(curlh);
      curlh = NULL;
      if(slist) curl_slist_free_all(slist);
      slist = NULL;

      sprintf(zs, "Received %s bytes of compressed CIF updates.",  commas(total_bytes));
      _log(GENERAL, zs);

      if(total_bytes == 0) return 1;
   
      _log(GENERAL, "Decompressing data...");
      sprintf(zs, "/bin/gunzip -f %s", filepathz);
      char * rc;
      if((rc = system_call(zs)))
      {
         _log(MAJOR, "Failed to uncompress file:  %s", rc);
         if((fp_result = fopen(filepathz, "r")))
         {
            char error_message[2048];
            size_t length;
            if((length = fread(error_message, 1, 2047, fp_result)) && error_message[0] == '<')
            {
               error_message[length] = '\0';
               _log(MAJOR, "Received message:\n%s", error_message);   
            }
            fclose(fp_result);
         }
         return 1;
      }
      _log(GENERAL, "Decompressed.");
   }
   else
   {
      strcpy(filepath, opt_filename);
   }

   if(!(fp_result = fopen(filepath, "r")))
   {
      _log(MAJOR, "Failed to open \"%s\" for reading.", filepath);
      return 1;
   }

   // Check if it's really an update
   {
      sprintf(zs, "grep -q \\\"Delete\\\" %s", filepath);
      word not_update = system(zs);
      if(not_update && (total_bytes < 32000000L)) not_update = false;
      _log(test_mode?GENERAL:DEBUG, "File is an update assessment: %s.", not_update?"File is not an update":"File is an update");
      if(fetch_all && !not_update)
      {
         _log(MAJOR, "Requested full timetable looks like an update.");
         fclose(fp_result);
         return 1;
      }
      if(!fetch_all && not_update)
      {
         _log(MAJOR, "Requested update looks like a full timetable.");
         fclose(fp_result);
         return 1;
      }
   }

   // Read enough of the file to find the datestamp
   char front[256];
   regmatch_t matches[3];

   if(!fread(front, 1, sizeof(front), fp_result))
   {
      fclose(fp_result);
      return 1;
   }
   else
   {
      front[255] = '\0';
      if(regexec(&match[0], front, 2, matches, 0))      
      {
         // Failed
         _log(MAJOR, "Failed to derive CIF file timestamp.");
         fclose(fp_result);
         return 1;
      }
      else
      {
         char zstamp[256];
         extract_match(front, matches, 1, zstamp, sizeof(zstamp));
         time_t stamp = atoi(zstamp);
         _log(test_mode?GENERAL:DEBUG, "Recovered timestamp: %s", time_text(stamp, 0));
         _log(test_mode?GENERAL:DEBUG, "Stored in file \"%s\"", filepath);
         if(regexec(&match[1], front, 2, matches, 0))
         {
            _log(MINOR, "Failed to derive CIF file sequence number.");
         }
         else
         {
            extract_match(front, matches, 1, zstamp, sizeof(zstamp));
            stats[Sequence] = atol(zstamp);
            _log(test_mode?GENERAL:DEBUG, "Sequence number: %s", commas_q(stats[Sequence]));
         }

         if(!test_mode && !opt_url && !opt_filename && (now < stamp || now - stamp > 36*60*60))
         {
            _log(MAJOR, "Timestamp %s is incorrect.  Received sequence number %d.", time_text(stamp, true), stats[Sequence]);
            fclose(fp_result);
            stats[Sequence] = 0;
            return 1;
         }
      }
   }
   fseeko(fp_result, 0, SEEK_SET);
   
   return 0;
}
Example #22
0
cAppliTarama::cAppliTarama(int argc,char ** argv) :
    cAppliWithSetImage(argc-1,argv+1,0)
{
    NoInit = "XXXXXXXXXX";

    // MemoArg(argc,argv);
    MMD_InitArgcArgv(argc,argv);
    std::string  aDir,aPat,aFullDir;
    std::string Aero;
    int  Zoom = 8;
    std::string  NOREP = "NO-REPERE";
    std::string Repere = NOREP;
    std::string DirOut = "TA";
    double   aZMoy = 0;
    int    aKNadir = -1;
    double aIncidMax = 1e5;
    bool   UnUseAXC = false;


    ElInitArgMain
    (
    argc,argv,
    LArgMain()  << EAMC(aFullDir,"Full Image (Dir+Pat)", eSAM_IsPatFile)
                    << EAMC(Aero,"Orientation", eSAM_IsExistDirOri),
    LArgMain()
                    << EAM(Zoom,"Zoom",true,"Resolution, (Def=8, must be pow of 2)",eSAM_IsPowerOf2)
                    << EAM(Repere,"Repere",true,"Local coordinate system as created with RepLocBascule",eSAM_IsExistFile)
                    << EAM(DirOut,"Out",true,"Directory for output (Deg=TA)")
                    << EAM(aZMoy,"ZMoy",true,"Average value of Z")
                    << EAM(aKNadir,"KNadir",true,"KBest image or Nadir (when exist)")
                    << EAM(aIncidMax,"IncMax",true,"Maximum incidence of image", eSAM_NoInit)
                    << EAM(UnUseAXC,"UnUseAXC",true,"Internal use for unanamorphosed ortho",eSAM_InternalUse)
    );

    if (!MMVisualMode)
    {
#if (ELISE_windows)
        replace( aFullDir.begin(), aFullDir.end(), '\\', '/' );
#endif
        SplitDirAndFile(aDir,aPat,aFullDir);

        StdCorrecNameOrient(Aero,aDir);


        MMD_InitArgcArgv(argc,argv);

        std::string aCom =  MM3dBinFile( "MICMAC" )
                + MMDir() + std::string("include/XML_MicMac/MM-TA.xml ")
                + std::string(" WorkDir=") +aDir +  std::string(" ")
                + std::string(" +PatternAllIm=") + QUOTE(aPat) + std::string(" ")
                + std::string(" +Zoom=") + ToString(Zoom)
                + std::string(" +Aero=") + Aero
                + std::string(" +DirMEC=") + DirOut
                ;

        if (EAMIsInit(&aIncidMax))
        {
            aCom = aCom + " +DoIncid=true +IncidMax=" + ToString(aIncidMax) + " " + " +ZMoy=" + ToString(AltiMoy()) + " " ;
;
        }

        if (EAMIsInit(&aKNadir))
            aCom = aCom + " +KBestMasqNadir=" + ToString(aKNadir);

        if (EAMIsInit(&aZMoy))
        {
            aCom = aCom + " +FileZMoy=File-ZMoy.xml"
                    + " +ZMoy=" + ToString(aZMoy);
        }
        if (EAMIsInit(&UnUseAXC)) aCom = aCom + " +UnUseAXC=" + ToString(UnUseAXC);

        if (Repere!=NOREP)
        {
            bool IsOrthoXCste;
            bool IsAnamXsteOfCart;
            if (RepereIsAnam(aDir+Repere,IsOrthoXCste,IsAnamXsteOfCart))
            {
                aCom =    aCom
                        +  std::string(" +DoAnam=true ")
                        +  std::string(" +DoIncid=true ")
                        +  std::string(" +ParamAnam=") + Repere;
            }
            else
            {
                aCom =     aCom    + std::string(" +Repere=") + Repere ;
            }
        }

#if (ELISE_windows)
		aCom = "\"" + aCom + "\"";
#endif		
        std::cout << "Com = " << aCom << "\n";
        mResult = system_call(aCom.c_str());

    }
    else
    {
       mResult = EXIT_SUCCESS;
    }
}
Example #23
0
static int do_emit_mimepart_body(FILE *fp_dest, SEND_BODYPART *part)
{
    char *fname_tmp, *fname_sel, cmd_buf[SLEN], *s;
    int rc, i;
    FILE *fp_src;

    rc = -1;
    fp_src = NULL;

    switch (mime_encoding_type(part->content_header[BP_CONT_ENCODING])) {

    case ENCODING_QUOTED:
	if ((fname_tmp = tempnam(temp_dir, "emm.")) == NULL) {
	    show_error("Cannot make temp file name.");
	    return -1;
	}
	MIME_ENCODE_CMD_QUOTED(cmd_buf, part->fname, fname_tmp);
	break;

    case ENCODING_BASE64:
	if ((fname_tmp = tempnam(temp_dir, "emm.")) == NULL) {
	    show_error("Cannot make temp file name.");
	    return -1;
	}
	MIME_ENCODE_CMD_BASE64(cmd_buf, part->fname, fname_tmp);
	break;

    case ENCODING_UUENCODE:
	if ((fname_tmp = tempnam(temp_dir, "emm.")) == NULL) {
	    show_error("Cannot make temp file name.");
	    return -1;
	}
	MIME_ENCODE_CMD_UUENCODE(cmd_buf, part->fname, fname_tmp);
	break;

    default:
	/* encoding not needed */
	fname_tmp = NULL;
	break;
    }

    if (fname_tmp == NULL) {
	fname_sel = part->fname;
    } else if ((i =  system_call(cmd_buf, 0)) == 0) {
	fname_sel = fname_tmp;
    } else {
	for (s = cmd_buf ; *s != '\0' && !isspace(*s) ; ++s)
	    ;
	*s = '\0';
	s = (cmd_buf[0] != '\0' ? basename(cmd_buf) : "encoder");
	show_error("Cannot encode \"%s\".  (\"%s\" exit status %d)",
		    basename(part->fname), s, i);
	goto done;
    }

    if ((fp_src = file_open(fname_sel, "r")) == NULL)
	goto done;
    if (file_copy(fp_src, fp_dest, fname_sel, "message body") < 0)
	goto done;
    if (file_close(fp_src, fname_sel) < 0)
	goto done;
    else 
        fp_src = NULL;

    rc = 0;

done:
    if (fp_src != NULL)
	(void) fclose(fp_src);
    if (fname_tmp != NULL) {
	(void) unlink(fname_tmp);
	free((malloc_t)fname_tmp);
    }
    return rc;
}
Example #24
0
File: task1b.c Project: mor91/lab4
void line_spliter(int digitSplit, int specialMarkSplit, int fileSplit, int file, char specialMark, int outputs, char filesnames[][10]){
 int files[5]; 
 int i;
        int file1;
        int file2;
        int file3;
        int file4;
        int file5;
	for(i=0; i<outputs;i++){
	    switch (i){
		case 0:
			/*file1=fopen(filesnames[0], "w+");*/
			file1=system_call(5, filesnames[0],2|64, 0644);
			files[0]=file1;
			break;
		case 1:
			/*file2=fopen(filesnames[1], "w+");*/
			file2=system_call(5, filesnames[1],2|64, 0644);
			files[1]=file2;
			break;
		case 2:
			
			/*file3=fopen(filesnames[2], "w+");*/
			file3=system_call(OPEN, filesnames[2],2|64, 0644);
			files[2]=file3;
			break;
		case 3:
			
			/*file4=fopen(filesnames[3], "w+");*/
			file4=system_call(OPEN, filesnames[3],2|64, 0644);
			files[3]=file4;
			break;
		case 4:
			
			/*file5=fopen(filesnames[4], "w+");*/
			file5=system_call(OPEN, filesnames[4],2|64, 0644);
			files[4]=file5;
			break;
 	    }	
	}
  char c;
  int isFirst=1;
  int line=1;
  char tempLine='0';
  if(fileSplit){
    system_call(SYS_READ,file,&c,1);

  }
  else system_call(SYS_READ,STDIN,&c,1);

  
  int currentFile;
  
  int fileNum=0;

  if(outputs){
	currentFile=file1;
  }
    while(c>0){
    switch(c){
      case '@':
	if(isFirst){
	  if(outputs){
		system_call(SYS_WRITE,currentFile,"1:",2);
		/*fprintf(currentFile,"1:" );*/
	  }
	  else /*printf("1:");*/
		system_call(SYS_WRITE,STDOUT,"1:",2);
        }
	if(outputs){
		system_call(SYS_WRITE,currentFile,"@",1);
		/*fprintf(currentFile,"@" );*/
	  }
	else /*printf("@");*/
		system_call(SYS_WRITE,STDOUT,"@",1);
	line++;
	tempLine=line+'0';
        if(outputs){
		system_call(SYS_WRITE,currentFile,"\n",1);
                /*fprintf(currentFile, "\n");*/
		fileNum=nextFile(fileNum,outputs);
		currentFile=files[fileNum];
		system_call(SYS_WRITE,currentFile,&tempLine,1);
		system_call(SYS_WRITE,currentFile,":",1);
		/*fprintf(currentFile, "%d:", line);*/
        }
	       	else {/*printf("\n%d:", line);*/
			system_call(SYS_WRITE,STDOUT,"\n",1);
			system_call(SYS_WRITE,STDOUT,&tempLine,1);
			system_call(SYS_WRITE,STDOUT,":",1);
		}
	isFirst=0;
	break;
      case '*':
	if(isFirst){
	  if(outputs){
		system_call(SYS_WRITE,currentFile,"1:",2);
		/*fprintf(currentFile,"1:" );*/
	  }
	  else /*printf("1:");*/
		system_call(SYS_WRITE,STDOUT,"1:",2);
        }
	if(outputs){
		system_call(SYS_WRITE,currentFile,"*",1);
		/*fprintf(currentFile,"*" );*/
	  }
	else /*printf("*");*/
		system_call(SYS_WRITE,STDOUT,"*",1);
	line++;
	tempLine=line+'0';
	if(outputs){
		system_call(SYS_WRITE,currentFile,"\n",1);
                /*fprintf(currentFile, "\n");*/
		fileNum=nextFile(fileNum,outputs);
		currentFile=files[fileNum];
		system_call(SYS_WRITE,currentFile,&tempLine,1);
		system_call(SYS_WRITE,currentFile,":",1);
		/*fprintf(currentFile, "%d:", line);*/
        }
	       	else {/*printf("\n%d:", line);*/
			system_call(SYS_WRITE,STDOUT,"\n",1);
			system_call(SYS_WRITE,STDOUT,&tempLine,1);
			system_call(SYS_WRITE,STDOUT,":",1);
		}
	isFirst=0;
	break;
      default: 
	if(isFirst){
	  if(outputs){
		system_call(SYS_WRITE,currentFile,"1:",2);
		/*fprintf(currentFile,"1:" );*/
	  }
	  else /*printf("1:");*/
		system_call(SYS_WRITE,STDOUT,"1:",2);
        }
	if(digitSplit && c<57 && c>48){
	  if(outputs){
		system_call(SYS_WRITE,currentFile,&c,1);
		/*fprintf(currentFile,"%c", c );*/
	  }
	  else /*printf("%c", c);*/
		system_call(SYS_WRITE,STDOUT,&c,1);
	  line++;
	  tempLine=line+'0';
	  if(outputs){
		system_call(SYS_WRITE,currentFile,"\n",1);
                /*fprintf(currentFile, "\n");*/
		fileNum=nextFile(fileNum,outputs);
		currentFile=files[fileNum];
		system_call(SYS_WRITE,currentFile,&tempLine,1);
		system_call(SYS_WRITE,currentFile,":",1);
		/*fprintf(currentFile, "%d:", line);*/
        }
	       	else {/*printf("\n%d:", line);*/
			system_call(SYS_WRITE,STDOUT,"\n",1);
			system_call(SYS_WRITE,STDOUT,&tempLine,1);
			system_call(SYS_WRITE,STDOUT,":",1);
		}
	isFirst=0;
	}
	else if( specialMarkSplit && c==specialMark){
	  if(outputs){
		/*fprintf(currentFile,"%c",specialMark );*/
		system_call(SYS_WRITE,currentFile,&specialMark,1);
	  }
	  else /*printf("%c",specialMark);*/
		system_call(SYS_WRITE,STDOUT,&specialMark,1);
	  line++;
	  tempLine=line+'0';
	  if(outputs){
		system_call(SYS_WRITE,currentFile,"\n",1);
                /*fprintf(currentFile, "\n");*/
		fileNum=nextFile(fileNum,outputs);
		currentFile=files[fileNum];
		system_call(SYS_WRITE,currentFile,&tempLine,1);
		system_call(SYS_WRITE,currentFile,":",1);
		/*fprintf(currentFile, "%d:", line);*/
        }
	       	else {/*printf("\n%d:", line);*/
			system_call(SYS_WRITE,STDOUT,"\n",1);
			system_call(SYS_WRITE,STDOUT,&tempLine,1);
			system_call(SYS_WRITE,STDOUT,":",1);
		}
	isFirst=0;
	}
	else {
	  if(outputs){
		system_call(SYS_WRITE,currentFile,&c,1);
		/*fprintf(currentFile,"%c", c );*/
	  }
	  else {/*printf("%c", c);
		printf("fvdfbv");*/
		system_call(SYS_WRITE,STDOUT,&c,1);}
	  isFirst=0;
	}
	break;
    }
    if(fileSplit){
      system_call(SYS_READ,file,&c,1);
    }
    else system_call(SYS_READ,STDIN,&c,1);

    if(c=='\n'|| c==' ')
        break;
  }
  int k;
  for(k=0;k<outputs;k++){
      /*close(files[k]);*/
	system_call(CLOSE,files[k]);
  }
}
Example #25
0
File: task1b.c Project: mor91/lab4
int main(int argc, char** argv){
  int digitSplit=0, specialMarkSplit=0, fileSplit=0, outputs=0;
  char specialMark;
  int file;
  char *fileName;
  /*int isEnd=0;*/
  char c;
  int i;

  for(i=1; i<argc; i++){
    c=argv[i][1];
    switch(c){
      case 'd': digitSplit=1;
	      break;
      case 's': specialMarkSplit=1;
		  i=i+1;
		  specialMark=argv[i][0];
	      break;
      case 'i': fileSplit=1;
		i=i+1;
		fileName=argv[i];
		fileName[strlen(argv[i])]='\0';
	      break;
       case 'o':i=i+1; 
		outputs=argv[i][0]-'0';
		system_call(SYS_WRITE,STDOUT,"number of output files: ",24);
		system_call(SYS_WRITE,STDOUT, &argv[i][0] ,1);
		system_call(SYS_WRITE,STDOUT,"\n",1);
		
		/*printf("number of output files:%d\n",outputs);*/
                
    }
    
  
  }
  
  char filesnames[5][10];
  if(outputs){
    int j;
    char temp[1];
    for(j=0; j<outputs; j++){

	system_call(SYS_WRITE,STDOUT,"Enter output file: ",19);
	temp[0]=j+1+'0';
	system_call(SYS_WRITE,STDOUT,&temp,1);
	system_call(SYS_WRITE,STDOUT,"\n",1);
	/*printf("Enter output file %d:\n", j+1);*/
	/*fgets(filenamei, sizeof(char)*10, stdin);*/
	system_call(SYS_READ,STDIN, &filesnames[j] ,10);
    }
  }
	/*system_call(SYS_WRITE,STDOUT,&filesnames[0],10);
	system_call(SYS_WRITE,STDOUT,"\n",1);
	system_call(SYS_WRITE,STDOUT,&filesnames[1],10);*/
  if(fileSplit){
    file=system_call(OPEN, fileName, 2, 0644);

  }
  else if(!fileSplit)
    system_call(SYS_WRITE,STDOUT,"Enter your text\n",16);
    /*printf("Enter your text\n");*/
  line_spliter(digitSplit,specialMarkSplit,fileSplit, file,specialMark, outputs, filesnames);
  return 0;
}
Example #26
0
PUBLIC int exitProcess()
{
	disp_color_str("api_exit_process@@@@", 0x3F);
	return system_call(NR_SYS_EXIT_PROCESS, 0, 0, 0, 0, 0);
}
Example #27
0
PUBLIC void  ttyOutputStr(const char* str)
{
	disp_color_str("api_ttyOutputstr@@@@", 0x3F);
	system_call(NR_SYS_TTY_OUTPUT_STR, (u32)str, 0, 0, 0, 0);
}
Example #28
0
File: editmsg.c Project: wfp5p/elm
/*
 * The editor used by edit_message() when "builtin" or "none" are selected.
 * Return 0 if successful, -1 on error.
 */
static int builtin_editor(const char *filename, SEND_HEADER *shdr)
{
    char linebuf[SLEN];		/* line input buffer			*/
    char wrapbuf[SLEN];		/* wrapped line overflow buffer		*/
    char tmpbuf[SLEN];		/* scratch buffer			*/
    FILE *fp;			/* output stream to "filename"		*/
    int rc;			/* return code from this procedure	*/
    int is_wrapped;		/* wrapped line flag			*/
    int err;			/* temp holder for errno		*/
    SIGHAND_TYPE (*oldint)();	/* previous value of SIGINT		*/
    SIGHAND_TYPE (*oldquit)();	/* previous value of SIGQUIT		*/
    SIGHAND_TYPE builtin_interrupt_handler();

    /* the built-in editor is not re-entrant! */
    assert(!builtin_active);

    /* initialize return code to failure */
    rc = -1;

    if ((fp = fopen(filename, "r+")) == NULL) {
	err = errno;
	sprintf(tmpbuf, catgets(elm_msg_cat, ElmSet, ElmCouldntOpenAppend,
	    "Couldn't open %s for update [%s]."),
	    filename, strerror(err));
	PutLine(-1, -1, tmpbuf);
	dprint(1, (debugfile,
	    "Error encountered trying to open file %s;\n", filename));
	dprint(1, (debugfile, "** %s **\n", strerror(err)));
	return rc;
    }

    /* skip past any existing text */
    fseek(fp, 0, SEEK_END);

    /* prompt user, depending upon whether file already has text */
    if (fsize(fp) > 0L)
	strcpy(tmpbuf, catgets(elm_msg_cat, ElmSet, ElmContinueEntering,
	    "\n\rContinue entering message."));
    else
	strcpy(tmpbuf, catgets(elm_msg_cat, ElmSet, ElmEnterMessage,
	    "\n\rEnter message."));
    strcat(tmpbuf, catgets(elm_msg_cat, ElmSet, ElmTypeElmCommands,
	"  Type Elm commands on lines by themselves.\n\r"));
    sprintf(tmpbuf+strlen(tmpbuf),
	catgets(elm_msg_cat, ElmSet, ElmCommandsInclude,
	"Commands include:  ^D or '.' to end, %cp to list, %c? for help.\n\r\n\r"),
	escape_char, escape_char);
    CleartoEOS();
    PutLine(-1, -1, tmpbuf);

    builtin_active = TRUE;
    builtin_interrupt_count = 0;

    oldint  = signal(SIGINT,  builtin_interrupt_handler);
    oldquit = signal(SIGQUIT, builtin_interrupt_handler);

    /* return location for interrupts */
    while (SETJMP(builtin_jmpbuf) != 0) {
	if (builtin_interrupt_count == 1) {
	    PutLine(-1, -1, catgets(elm_msg_cat, ElmSet,
		ElmEditmsgOneMoreCancel,
		"(Interrupt. One more to cancel this letter.)\n\r"));
	} else {
	    PutLine(-1, -1, catgets(elm_msg_cat, ElmSet, ElmEditmsgCancelled,
		"(Interrupt. Letter canceled.)\n\r"));
	    goto done;
	}
    }

    for (;;) {

	/* re-open file if it was closed out on a call to an external editor */
	if (fp == NULL) {
	    if ((fp = fopen(filename, "a+")) == NULL) {
		err = errno;
		sprintf(tmpbuf, catgets(elm_msg_cat, ElmSet,
		    ElmCouldntOpenAppend,
		    "Couldn't open %s for update [%s]."),
		    filename, strerror(err));
		PutLine(-1, -1, tmpbuf);
		dprint(1, (debugfile,
		    "Error encountered trying to open file %s;\n", filename));
		dprint(1, (debugfile, "** %s **\n", strerror(err)));
		goto done;
	    }
	    PutLine(-1, -1, catgets(elm_msg_cat, ElmSet, ElmPostEdContinue,
		"(Continue entering message.  Type ^D or '.' on a line by itself to end.)\n\r"));
	}

	linebuf[0] = '\0';
	wrapbuf[0] = '\0';
	is_wrapped = 0;

more_wrap:
	if (wrapped_enter(linebuf, wrapbuf, -1, -1, fp, &is_wrapped) != 0)
	    break;

	if (is_wrapped) {
	    fprintf(fp, "%s\n", linebuf);
	    NewLine();
	    (void) strcpy(linebuf, wrapbuf);
	    wrapbuf[0] = '\0';
	    goto more_wrap;
	}

	/* reset consecutive interrupt counter */
	builtin_interrupt_count = 0;

	/* a lone "." signals end of text */
	if (strcmp(linebuf, ".") == 0)
	    break;

	/* process line of text */
	if (linebuf[0] != escape_char) {
	   fprintf(fp, "%s\n", linebuf);
	   NewLine();
	   continue;
	}

	/* command character was escaped */
	if (linebuf[1] == escape_char) {
	    fprintf(fp, "%s\n", linebuf+1);
	    continue;
	}

	switch (tolower(linebuf[1])) {

	case '?':
	    tilde_help();
	    break;

	case 't':
	    get_with_expansion("\n\rTo: ",
			shdr->to, shdr->expanded_to, linebuf);
	    break;

	case 'b':
	    get_with_expansion("\n\rBcc: ",
			shdr->bcc, shdr->expanded_bcc, linebuf);
	    break;

	case 'c':
	    get_with_expansion("\n\rCc: ",
			shdr->cc, shdr->expanded_cc, linebuf);
	    break;

	case 's':
	    get_with_expansion("\n\rSubject: ",
			shdr->subject, (char *)NULL, linebuf);
	    break;

	case 'h':
	    get_with_expansion("\n\rTo: ",
			shdr->to, shdr->expanded_to, (char *)NULL);
	    get_with_expansion("Cc: ",
			shdr->cc, shdr->expanded_cc, (char *)NULL);
	    get_with_expansion("Bcc: ",
			shdr->bcc, shdr->expanded_bcc, (char *)NULL);
	    get_with_expansion("Subject: ",
			shdr->subject, (char *)NULL, (char *)NULL);
	    break;

	case 'r':
	    read_in_file(fp, linebuf+2, 1);
	    break;

	case 'e':
	    if (e_editor[0] == '\0') {
		PutLine(-1, -1, catgets(elm_msg_cat, ElmSet, ElmDontKnowEmacs,
		    "\n\r(Don't know where Emacs would be. Continue.)\n\r"));
		break;
	    }
	    NewLine();
	    fclose(fp);
	    fp = NULL;
	    (void) edit_message(filename, shdr, e_editor);
	    break;

	case 'v':
	    NewLine();
	    fclose(fp);
	    fp = NULL;
	    (void) edit_message(filename, shdr, v_editor);
	    break;

	case 'o':
	    PutLine(-1, -1, catgets(elm_msg_cat, ElmSet, ElmEnterNameEditor,
		"\n\rPlease enter the name of the editor: "));
	    if (enter_string(tmpbuf, sizeof(tmpbuf), -1, -1, ESTR_ENTER) < 0
			|| tmpbuf[0] == '\0') {
		PutLine(-1, -1, catgets(elm_msg_cat, ElmSet, ElmSimpleContinue,
		    "(Continue.)\n\r"));
		break;
	    }
	    NewLine();
	    fclose(fp);
	    fp = NULL;
	    (void) edit_message(filename, shdr, tmpbuf);
	    break;

	case '<':
	    NewLine();
	    if (strlen(linebuf) < 3) {
		PutLine(-1, -1, catgets(elm_msg_cat,
		    ElmSet, ElmUseSpecificCommand,
		   "(You need to use a specific command here. Continue.)\n\r"));
		break;
	    }
	    sprintf(tmpbuf, "%s%s.%d", temp_dir, temp_edit, getpid());
	    sprintf(linebuf+strlen(linebuf), " >%s 2>&1", tmpbuf);
	    (void) system_call(linebuf+2, SY_COOKED|SY_ENAB_SIGINT|SY_DUMPSTATE);
	    read_in_file(fp, tmpbuf, 0);
	    (void) unlink(tmpbuf);
	    break;

	case '!':
	    NewLine();
	    (void) system_call(
		(strlen(linebuf) < 3 ? (char *)NULL : linebuf+2),
		SY_COOKED|SY_USER_SHELL|SY_ENAB_SIGINT|SY_DUMPSTATE);
	    PutLine(LINES, 0, catgets(elm_msg_cat, ElmSet, ElmSimpleContinue,
		"(Continue.)\n\r"));
	    break;

	case 'm': /* same as 'f' but with leading prefix added */
	case 'f': /* this can be directly translated into a
			 'readmsg' call with the same params! */
	    NewLine();
	    read_in_messages(fp, linebuf+1);
	    break;

	case 'p': /* print out message so far */
	    print_message_so_far(fp, shdr);
	    break;

	default:
	    sprintf(tmpbuf, catgets(elm_msg_cat, ElmSet, ElmDontKnowChar,
		"\n\r(Don't know what %c%c is. Try %c? for help.)\n\r"),
		 escape_char, linebuf[1], escape_char);
	    PutLine(-1, -1, tmpbuf);
	    break;

	}

    }

    PutLine(-1, -1, catgets(elm_msg_cat, ElmSet, ElmEndOfMessage,
	"\n\r<end-of-message>\n\r\n\r\n\r\n\r"));
    rc = 0;

done:
    (void) signal(SIGINT,  oldint);
    (void) signal(SIGQUIT, oldquit);
    if (fp != NULL)
	fclose(fp);
    builtin_active = FALSE;
    return rc;
}
Example #29
0
int Tawny_main(int argc,char ** argv)
{
    // MemoArg(argc,argv);
    MMD_InitArgcArgv(argc,argv);
    std::string  aDir;

    int mDeq = 1;
    Pt2di mDeqXY(-1,-1);
    bool mAddCste = false;
    int mDegRap = 0;
    Pt2di mDegRapXY(-1,-1);
    bool mRapGlobPhys = true;
    double mDynGlob=1.0;

    std::string mImPrio0 = ".*";
    int mSzV = 1;
    double mCorrThresh = 0.8;
    double mNbPerIm = 1e4;
    bool  DoL1Filter=false;

    double  aSatThresh = 1e9;
    string aNameOut="Ortho-Eg-Test-Redr.tif";

    ElInitArgMain
    (
    argc,argv,
    LArgMain()   << EAMC(aDir,"Data directory", eSAM_IsDir),
    LArgMain()   << EAM(mDeq,"DEq",true,"Degree of equalization (Def=1)")
                 << EAM(mDeqXY,"DEqXY",true,"Degree of equalization, if diff in X and Y")
                 << EAM(mAddCste,"AddCste",true,"Add unknown constant for equalization (Def=false)", eSAM_IsBool)
                 << EAM(mDegRap,"DegRap",true,"Degree of rappel to initial values, Def = 0")
                 << EAM(mDegRapXY,"DegRapXY",true,"Degree of rappel to initial values, Def = 0")
                 << EAM(mRapGlobPhys,"RGP",true,"Rappel glob on physically equalized, Def = true")
                 << EAM(mDynGlob,"DynG",true,"Global Dynamic (to correct saturation problems)")
                 << EAM(mImPrio0,"ImPrio",true,"Pattern of image with high prio, def=.*", eSAM_IsPatFile)
                 << EAM(mSzV,"SzV",true,"Sz of Window for equalization (Def=1, means 3x3)")
                 << EAM(mCorrThresh,"CorThr",true,"Threshold of correlation to validate homologous (Def 0.7)")
                 << EAM(mNbPerIm,"NbPerIm",true,"Average number of point per image (Def = 1e4)")
                 << EAM(DoL1Filter,"L1F",true,"Do L1 Filter on couple, def=true (change when process is blocked)", eSAM_IsBool)
                 << EAM(aSatThresh,"SatThresh",true,"Threshold determining saturation value (pixel >SatThresh will be ignored)")
                 << EAM(aNameOut,"Out",true,"Name of output file (in the folder)", eSAM_IsOutputFile)
    );

    if (!MMVisualMode)
    {
#if (ELISE_windows)
        replace( aDir.begin(), aDir.end(), '\\', '/' );
#endif

        if ( (!aDir.empty()) && (*aDir.rbegin() != '/') )
            aDir.append("/");

        if (! EAMIsInit(&mDeqXY))
            mDeqXY = Pt2di(mDeq,mDeq);

        if (! EAMIsInit(&mDegRapXY))
            mDegRapXY = Pt2di(mDegRap,mDegRap);

        Pt2di aDegCste = mAddCste  ? Pt2di(0,0) : Pt2di(-1,-1);

        MMD_InitArgcArgv(argc,argv);

        std::string aCom =    MM3dBinFile( "Porto" )
                + MMDir() +std::string("include/XML_MicMac/Param-Tawny.xml ")
                + std::string(" %WD=") + aDir
                + std::string(" +DR1X=") + ToString(mDeqXY.x)
                + std::string(" +DR1Y=") + ToString(mDeqXY.y)
                + std::string(" +DR0X=") + ToString(aDegCste.x)
                + std::string(" +DR0Y=") + ToString(aDegCste.y)
                + std::string(" +DegRapX=") + ToString(mDegRapXY.x)
                + std::string(" +DegRapY=") + ToString(mDegRapXY.y)
                + std::string(" +RapGlobPhys=") + ToString(mRapGlobPhys)
                + std::string(" +DynGlob=") + ToString(mDynGlob)
                + std::string(" +NameOrtho=") + aNameOut
                ;

        if (mImPrio0!="") aCom = aCom+ " +ImPrio="+QUOTE(mImPrio0);
        if (EAMIsInit(&mSzV)) aCom  = aCom + " +SzV=" + ToString(mSzV);
        if (EAMIsInit(&mNbPerIm)) aCom  = aCom + " +NbPerIm=" + ToString(mNbPerIm);
        if (EAMIsInit(&mCorrThresh)) aCom  = aCom + " +CorrThresh=" + ToString(mCorrThresh);

        if (!DoL1Filter) aCom  = aCom +" +DoL1Filter=false ";

        std::cout << aCom << "\n";
        int aRes = system_call(aCom.c_str());

        BanniereMM3D();
        return aRes;
    }
    else return EXIT_SUCCESS;
}
Example #30
0
PUBLIC ComboKey* readComboKey()
{
	return (ComboKey*)system_call(NR_SYS_READ_COMBO_KEY, 0, 0, 0, 0, 0);
}