Example #1
0
int main() {
	struct confModules *foo;
	int x;
	
	foo=newConfModules();
	addAlias(foo,"eth0","eepro100",CM_REPLACE);
	addAlias(foo,"eth0","tulip",CM_COMMENT);
	addOptions(foo,"eth0","debug=foo",0);
	addLine(foo,"alias parport_lowlevel parport_pc",CM_COMMENT);
	writeConfModules(foo,"foomod");
	printf("=%s=\n",getAlias(foo,"eth0"));
	printf("=%s=\n",getAlias(foo,"scuzzy_hostadapter"));
	freeConfModules(foo);
}
Example #2
0
//--------------------------------------------------------------
StreamAsset::StreamAsset(AssetManagerInterface* man, const string& _name, StreamType _type, string _url, string _username, string _password) : BaseMediaAsset(man) {
    canSource = true;
    
    assetType  = MEDIA_ASSET_STREAM;
    streamType = _type;

    addAlias(_name);
    
    url        = _url;
    username   = _username;
    password   = _password;
    
    isIpVideo = streamType == STREAM_TYPE_IPCAM;
    
    if(isIpVideo) {
        ipcam = ofPtr<ofxIpVideoGrabber>(new ofxIpVideoGrabber());
        ipcam->setURI(url);
        ipcam->setUsername(username);
        ipcam->setPassword(password);
    } else {
        qtcam = ofPtr<ofVideoPlayer>(new ofVideoPlayer());
        qtcam->loadMovie(url); // TODO: construct correct user/pass string
    }
    
    addOscMethod("open");
    addOscMethod("close");
}
Example #3
0
SphereLoader::SphereLoader()
    :BaseLoader(),
     positions(initData(&positions,"position","Sphere centers")),
     radius(initData(&radius,"listRadius","Radius of each sphere")),
     d_scale(initData(&d_scale,"scale","Scale applied to sphere positions & radius")),
     d_translation(initData(&d_translation,"translation","Translation applied to sphere positions"))

{
    addAlias(&positions,"sphere_centers");
}
//--------------------------------------------------------------
GrabberAsset::GrabberAsset(AssetManagerInterface* man, const string& _name, int _devId, int _width, int _height) : BaseMediaAsset(man){
    
    canSource = true;
    
    assetType = MEDIA_ASSET_GRABBER;

    addAlias(_name);
    
    width  = _width;
    height = _height;
    devId  = _devId;
    grabber = ofPtr<ofVideoGrabber>(new ofVideoGrabber());
    
    addOscMethod("open");
    addOscMethod("close");
    
    //        grabber->initGrabber(width, height);
}
Example #5
0
CDialogIrcSettings::CDialogIrcSettings( QWidget* parent ) :
	QDialog( parent ),
	ui( new Ui::CDialogIrcSettings )
{
	ui->setupUi( this );

	setWindowFilePath( tr( "Settings" ) );

//TODO:	ui->treeWidgetColors->setItemDelegate(new ColorItemDelegate(ui->treeWidgetColors));
	ui->treeWidgetShortcuts->setItemDelegate( new ShortcutItemDelegate( ui->treeWidgetShortcuts ) );
//TODO:		ui->treeWidgetColors->header()->setSectionResizeMode(ColorColumns::Message, QHeaderView::ResizeToContents);
	ui->treeWidgetShortcuts->header()->setSectionResizeMode( ShortcutColumns::Description, QHeaderView::ResizeToContents );
	ui->treeWidgetShortcuts->expandItem( ui->treeWidgetShortcuts->topLevelItem( 0 ) );
	ui->treeWidgetShortcuts->expandItem( ui->treeWidgetShortcuts->topLevelItem( 1 ) );
	proxyModel = new SortFilterProxyModel( ui->treeViewAliases );
	sourceModel = new QStandardItemModel( proxyModel );
	proxyModel->setSourceModel( sourceModel );
	ui->treeViewAliases->setModel( proxyModel );
	ui->treeViewAliases->setItemDelegateForColumn( 2, new CloseDelegate( ui->treeViewAliases ) );

	loadSettings();

	connect( ui->checkBoxConnectOnStartup, SIGNAL( toggled( bool ) ), this, SLOT( enableApply() ) );
	connect( ui->fontComboBox, SIGNAL( currentFontChanged( QFont ) ), this, SLOT( enableApply() ) );
	connect( ui->spinBoxFontSize, SIGNAL( valueChanged( int ) ), this, SLOT( enableApply() ) );
	connect( ui->checkBoxStripNicks, SIGNAL( toggled( bool ) ), this, SLOT( enableApply() ) );
	connect( ui->checkBoxHighlightSounds, SIGNAL( toggled( bool ) ), this, SLOT( enableApply() ) );
	connect( ui->checkBoxTimeStamp, SIGNAL( toggled( bool ) ), this, SLOT( enableApply() ) );
	connect( ui->checkBoxDarkTheme, SIGNAL( toggled( bool ) ), this, SLOT( enableApply() ) );
	connect( ui->spinBoxBlockCount, SIGNAL( valueChanged( int ) ), this, SLOT( enableApply() ) );
//TODO:		connect(ui->treeWidgetColors, SIGNAL(clicked(QModelIndex)), this, SLOT(enableApply()));
	connect( ui->treeWidgetShortcuts, SIGNAL( clicked( QModelIndex ) ), this, SLOT( enableApply() ) );
	connect( ui->toolButtonAddAliases, SIGNAL( clicked() ), this, SLOT( addAlias() ) );
	connect( ui->treeViewAliases, SIGNAL( clicked( QModelIndex ) ), this, SLOT( onAliasClicked( QModelIndex ) ) );
	connect( ui->treeViewAliases, SIGNAL( activated( QModelIndex ) ), this, SLOT( enableApply() ) );
	connect( ui->lineEditAliasesFilter, SIGNAL( textEdited( QString ) ), proxyModel, SLOT( setFilterWildcard( QString ) ) );

	connect( ui->pushButtonApply, SIGNAL( clicked() ), this, SLOT( saveSettings() ) );
	ui->pushButtonApply->setEnabled( false );
}
Example #6
0
//--------------------------------------------------------------
PlayerAsset::PlayerAsset(AssetManagerInterface* man, const string& _name) : BaseMediaAsset(man), PlayerAssetInterface(man) {
    
    canSource = true;
    
    assetType = MEDIA_ASSET_PLAYER;
    
    addAlias(_name);
    
    player = ofPtr<ofxVideoBufferPlayer>(new ofxVideoBufferPlayer());
    
    currentAssetLink = NULL;
    
    //addOscMethod("buffer");

    addOscMethod("play");
    addOscMethod("start");
    addOscMethod("stop");
    addOscMethod("pause");
    
    addOscMethod("loopmode");
    
    addOscMethod("looppoints");
    addOscMethod("looppointstart");
    addOscMethod("looppointend");
    
    addOscMethod("looppointsn");
    addOscMethod("looppointstartn");
    addOscMethod("looppointendn");
    
    addOscMethod("frame");
    addOscMethod("framen");    
    
    addOscMethod("speed");
    
    addOscMethod("dump");
    
}
Example #7
0
MainWindow::MainWindow(QApplication &app, ElementDatabase& db)
	: QMainWindow(),
	  Ui::MainWindow(),
	  mApp(&app), 
	  mCompleter(NULL),
	  mLangPath(":/lang"),
	  mInputData(db),
	  mDB(&db),
	  mDataVisualizer(this, db)
{
	mApp->installTranslator(&mTranslator);
#ifdef DEBUG
	if ( ! mLangPath.exists() ) 
		std::cerr << "Unable to determine language directory !" << std::endl;
#endif

	setupUi(this);

	mFormulaDefaultPalette = ntrFormula->palette();
	tblResult->setModel(&mModel);

	// action setup (menu bar)
	menuFile = new QMenu(menubar);
	menuTools = new QMenu(menubar);
	menuLang = new QMenu(menubar);
	menuHelp = new QMenu(menubar);
	addActions();
	connect(actionQuit, SIGNAL(triggered()), &app, SLOT(quit()));
	connect(&app, SIGNAL(lastWindowClosed()), &app, SLOT(quit()));
	connect(actionAbout_Qt, SIGNAL(triggered()), &app, SLOT(aboutQt()));
	connect(actionAbout, SIGNAL(triggered()), this, SLOT(about()));
	connect(actionVisualizeData, SIGNAL(triggered()), &mDataVisualizer, SLOT(show()));
	connect(actionUseSystemLocale, SIGNAL(triggered()), this, SLOT(useSystemLocaleTriggered()));
	selectDefaultLang();
	actionUseSystemLocale->trigger();

	// action setup result table
	connect(actionExpandAll, SIGNAL(triggered()), this, SLOT(expandAll()));
	connect(actionCollapseAll, SIGNAL(triggered()), this, SLOT(collapseAll()));
	connect(actionSelectAll, SIGNAL(triggered()), tblResult, SLOT(selectAll()));
	connect(actionCopySelection, SIGNAL(triggered()), this, SLOT(copyResultTableSelection()));
	connect(tblResult, SIGNAL(expanded(const QModelIndex&)), this, SLOT(expandItem(const QModelIndex&)));
	connect(tblResult, SIGNAL(collapsed(const QModelIndex&)), this, SLOT(expandItem(const QModelIndex&)));

	// populate list of all known GUI input fields
	mFormEntries.append(FormEntry(ntrFormula,   "currentText", lblFormula));
	mFormEntries.append(FormEntry(ntrDensity,   "value", lblDensity));
	mFormEntries.append(FormEntry(ntrXrayEn,    "value", lblXrayEn));
	mFormEntries.append(FormEntry(ntrNeutronWl, "value", lblNeutronWl));
	saveInitialInput();

	// button connectors
	connect(btnClear, SIGNAL(clicked()), this, SLOT(resetInput()));
	connect(btnAddAlias, SIGNAL(clicked()), this, SLOT(addAlias()));
	connect(btnCalc, SIGNAL(clicked()), this, SLOT(doCalc()));

	if (ntrFormula->lineEdit()) {
		mCompleter = new FormulaCompleter(db, ntrFormula->lineEdit(), btnCalc);
		connect(ntrFormula->lineEdit(), SIGNAL(returnPressed()), btnCalc, SLOT(animateClick()));
	}
	connect(ntrDensity, SIGNAL(editingFinished()), btnCalc, SLOT(animateClick()));
	connect(ntrXrayEn, SIGNAL(editingFinished()), btnCalc, SLOT(animateClick()));
	connect(ntrNeutronWl, SIGNAL(editingFinished()), btnCalc, SLOT(animateClick()));

	connect(lblFormattedFormula, SIGNAL(linkActivated(const QString&)), 
		this, SLOT(showElementData(const QString&)));
	connect(&mDataVisualizer, SIGNAL(elementLinkActivated(const QString&)), 
		this, SLOT(showElementData(const QString&)));
}
Example #8
0
void initCmds() {
	int lastParams;
	char *lastParamsFlags;
	char *lastExpr;

	addNew  ("help",            "gf.help(\"\")",           0, ""     );
	const char * const *helpPages=stringsGetContent("help");
	do {
		if (!**helpPages)
			continue;
		char cmd[50], expr[50];
		sprintf(cmd, "help %s", *helpPages);
		sprintf(expr, "gf.help(\"%s\")", *helpPages);
		addNew(cmd,               expr,                      0, ""     );
	} while (*++helpPages);

	addNew  ("history",         "gf.history()",            0, ""     );
	addNew  ("map ",            "gf.map(%)",              -2, "s"    );
	addNew  ("new ",            "gf.new(%)",               1, ""     );
	addAlias("n ");
	addNew  ("close",           "gf.close()",              0, ""     );
	addNew  ("open ",           "gf.open(%)",              1, "p"    );
	addAlias("o ");
	addNew  ("quit",            "gf.quit()",               0, ""     );
	addAlias("q");
	addAlias("exit");
	addNew  ("rotate ",         "gf.rotate(%)",           -3, ""     );
	addAlias("rot ");
	addNew  ("reset rotation",  "gf.resetRotation()",      0, ""     );
	addAlias("reset rot");
	addNew  ("reset colors",    "gf.resetColors()",        0, ""     );
	addNew  ("reset boundary",  "gf.resetBoundary()",      0, ""     );
	addNew  ("rmap ",           "gf.rmap(%)",             -3, "s-"   );

	consoleCmdSetUpdateCmds();

	addNew  ("source ",         "gf.source(%)",            1, "p"    );
	addAlias("so ");
	addNew  ("vertex add",      "gf.vertexSelect(gf.vertexAdd())",
	                                                       0, ""     );
	addAlias("vert add");
	addNew  ("vertex add ",
	  "gf.vertexSelect(gf.vertexAdd(gf.posRotateBack(tuple(([%]+[0]*100)[:gf.get_dimen()]))))",
	                                                 INT_MIN, ""     );
	addAlias("vert add ");
	addNew  ("vertex deselect", "gf.vertexDeselect()",     0, ""     );
	addAlias("vertex desel");
	addAlias("vert deselect");
	addAlias("vert desel");
	addNew  ("vertex move ",
	  "gf.vertexSetPos(gf.vertexSelected(),tuple(map(sum,zip(gf.posRotateBack(tuple(([%]+[0]*100)[:gf.get_dimen()])),gf.vertexGetPos(gf.vertexSelected())))))",
	                                                 INT_MIN, ""    );
	addAlias("vert move ");
	addNew  ("vertex next",     "gf.vertexNext()",         0, ""     );
	addAlias("vert next");
	addNew  ("vertex previous", "gf.vertexPrevious()",     0, ""     );
	addAlias("vertex prev");
	addAlias("vert previous");
	addAlias("vert prev");
	addNew  ("vertex remove",
	  "gf.vertexRemove(gf.vertexSelected())",              0, ""     );
	addAlias("vertex rm");
	addAlias("vert remove");
	addAlias("vert rm");
	addNew  ("vertex select",   "gf.vertexSelected()",     0, ""     );
	addAlias("vertex sel");
	addNew  ("vertex select ",  "gf.vertexSelect(%)",      1, ""     );
	addAlias("vertex sel ");
	addAlias("vert select ");
	addAlias("vert sel ");
	addNew  ("write ",          "gf.write(%)",             1, "p"    );
	addAlias("w ");
}
Example #9
0
void runInternal(int m){
int result;
char *promptBuff;
promptBuff = NULL;
	switch(m){
		case 0:
			home = getenv("HOME");
			int i = chdir(home);
			if(i<0) printf("Couldn't restore\n");
			else{
				printf("directory changed\n");
				printf("HOME: %s\n", home);
			}
			exit(0);
		case 1:
			/*if(par[1] != NULL){
					printf("%s is an Unknown command 2\n", *par);
			}
			else{*/
				printf("PATH = %s\n", getenv("PATH"));
				/*}*/
			break;
		case 2:
			if(par[1] == NULL){
					printf("%s is an Unknown command 3\n", *par);
			}
			else{
				int newPath = setenv(par[1], par[1], 0);
				printf("%d", newPath);
				/*const char* path = getenv("PATH");
				printf("PATH :%s\n",(path!=NULL)? path : "getenv returned NULL");*/
			}
			break;
		case 3:
			
			result= 0;
			if(par[1] == NULL){
				chdir("..");
			}
			else{
				result = chdir(par[1]);
				if (getcwd(promptBuff, sizeof(par[1])) != NULL);
				else{
					printf("FAILED\n");
				}
				if(result == 0){
					printf("Directory changed to %s\n", par[1]);
				}	
				else{
					switch(result){
					case EACCES: perror("Permission denied");
						break;
					case EIO:	 perror("An input output error occured");
						break;
					case ENAMETOOLONG: perror("Path is too long");
						break;
					case ENOTDIR: perror("A component of path not a directory"); 
						break;
					case ENOENT: perror("No such file or directory"); printf("enoent\n");
      
					default: printf("Couldn't change directory to %s", par[1] ); 
					}
				}
				
			}
			break;
		case 4:
			printHistory();
			break;
		case 5: if(par[1] == NULL || par[2] == NULL) {
			printAliases();
		} else {
			addAlias();
		}	
	}	
	
}
Example #10
0
void CliArgumentParser::addSwitch(CliArgumentParser::string name, CliArgumentParser::string alias, int parameter, bool optionalParameters)
{
	addSwitch(name, parameter, optionalParameters);
	addAlias(name, alias);
}
Example #11
0
void CliArgumentParser::addAlias(CliArgumentParser::string name, CliArgumentParser::string alias, CliArgumentParser::string alias2)
{
	addAlias(name, alias);
	addAlias(name, alias2);
}
Example #12
0
void aliasAdd(char* name, char* word) {
    addAlias(name, word);
}
Example #13
0
/*
 * RunBuiltInCmd
 *
 * arguments:
 *   commandT *cmd: the command to be run
 *
 * returns: none
 *
 * Runs a built-in command.
 */
static void
RunBuiltInCmd(commandT* cmd)
{
  if(strcmp(cmd->argv[0],"cd")==0){
    changeWorkingDir(cmd->argv[1]); 
  }
  /* "pwd" command*/ 
  else if(strcmp(cmd->argv[0],"pwd")==0){
   char *dir = getCurrentWorkingDir();
   printf("%s\n",dir);   
   free(dir);
  }
  else if(!strcmp(cmd->argv[0],"jobs")){
   bgjobL* job = bgjobs;
   while (job != NULL){
    if (!strcmp(job->status, "Running")){
      printf("[%d]   %s                 %s &\n", job->jid, job->status, job->name);
    }
    else{
      printf("[%d]   %s                 %s\n", job->jid, job->status, job->name);
    }
    job = job->next;
  }
 }
  else if (!strcmp(cmd->argv[0],"fg")){
    bgjobL* job;
    if(cmd->argv[1] != NULL){
     job = GetJobFromJid(atoi(cmd->argv[1]));
    }
    else{
      job = GetMRJob();
    }
    
    //bring bg process to foreground
    if (job != NULL){
      tcsetpgrp(job->pid, STDIN_FILENO);
      crpid = job->pid;
      crName = job->name;
      DeleteJob(job->pid);
      kill(-crpid, SIGCONT);
      int status = 0;
      waitpid(crpid, &status, WUNTRACED);
      crpid = 0;
      crName = NULL;
    }
  }
  else if (!strcmp(cmd->argv[0],"bg")){
    bgjobL* job;
    if(cmd->argv[1] != NULL){
     job = GetJobFromJid(atoi(cmd->argv[1]));
     if (job != NULL){
      kill(job->pid, SIGCONT);
      job->status = "Running";
     }
    }
    else{
      job = GetMRJob();
      if (job != NULL){
	kill(job->pid, SIGCONT);
      job->status = "Running";
      }
    }
  }
  else if(!strcmp(cmd->argv[0],"alias")){
  
      addAlias(cmd);

  }
  else if(!strcmp(cmd->argv[0],"unalias")){
  
      deleteAlias(cmd->argv[1]);

  }
   else if(!strcmp(cmd->argv[0],"exit")){
  
      return;

  }
} /* RunBuiltInCmd */
Example #14
0
/***********************
 *                     *
 * ProcessCmd cmd      *
 *                     *
 ***********************/ 
int
ProcessCmd(PARSE_RESULT *result)
{
     CT_EXPR     *ctExpr     = NULL;
     COMB_EXPR   *combExpr   = NULL;
     M_INSTR     *macroCode  = NULL;
     CT_VAR_BASE *var_base   = NULL;
     ST_TYPE     *st_type;
     ST_KEY       funKey;

     switch (result->tag) {
	case SETCOMMAND: 
	  ge_ProcessSetCommand(result->info.setcommand);
	  break;
	case COMMAND: 
	  return (ge_ProcessCommand(result->info.command));
	  break;
	case QUERY:
	  ge_ProcessQuery(result->info.query);
	  break;
	case DATA:
	  addDatatype(result->info.data);
	  break;
	case ALIAS:
	  addAlias (result->info.alias);
	  break;

	case DEF:
#if 0
printf("RHS PARSE TREE:\n");
display_PE_EXPR(result->info.def->expr, 0);
#endif
 	  funKey = st_AddFunction(result->info.def);

	  /* typecheck the term logic parse tree */
	  tc_open_typechecker();
	  tc_typecheck_PE_DEF(result->info.def, funKey);
	  /* if this point reached then typecheck of def was successful */

	  ctExpr = pmTranslate(result->info.def->expr,1);

          if ( printCT_EXPR ) {
 	      printMsg(MSG, "\nCore term logic for the function is: \n");
              printMsg(MSG, "def %s{%L} = %V =>", result->info.def->id,
                                                result->info.def->macros,
                                                var_base);
 	      printMsg(MSG, "%r\n", ctExpr);
          }   /*  fi  */

          /* close after typecheck & patt translation are complete */
          /* we need to remove DEF if patt translation fails */
	  tc_close_typechecker(0);

	  ct_TranslateOpen();

	  /* if function definition contains any macros, we must add the   */
	  /* environment to the variable base                              */
	  if (result->info.def->macros) {
	       var_base = VarBasePairNew(parseHeapDesc, 
					 vb_pmTranslate(result->info.def->var_base),
					 &ct_vb_env);
	  }
	  else 
	       var_base = vb_pmTranslate(result->info.def->var_base);

	  ctExpr = ctPreTranslate (ctExpr);     /* [#@] */

	  combExpr = ctTranslate(result->info.def->id,
				 var_base,
				 ctExpr);

	  printMsg(MSG,"Function added:  %s%S",st_KeyToName(funKey),st_GetTypeSig(funKey));

	  macroCode = Compile(result->info.def->id, combExpr); 
	  CodeTableAdd(result->info.def->id, combExpr,  
		       macroCode);

	  ct_TranslateClose();
	  break;

	case EXPR:
#if 0
printf("PARSE TREE:\n");
display_PE_EXPR(result->info.expr, 0);
#endif
	  /* typecheck the term logic parse tree */
	  tc_open_typechecker();
	  st_type = tc_typecheck_PE_EXPR(result->info.expr);
	  /* if this point reached then typecheck was successful */
	  /* don't close typechecker until AFTER result st_type is printed below */

	  ctExpr = pmTranslate(result->info.expr,0);

          if ( printCT_EXPR )
	      printMsg(MSG, "\nCore term logic for the expression is: \n%r\n", ctExpr);

	  ct_TranslateOpen();

	  ctExpr = ctPreTranslate (ctExpr);     /* [#@] */

	  combExpr = ctTranslate(NULL, vb_pmTranslate(VBbang()), ctExpr);

	  mc_MachineOpen();
	  combExpr = Evaluate(combExpr, st_type);
	  kludge = 1;
	  combExprPrint(combExpr,PP_MAX_SHOW_DEPTH,PP_MAX_RECORD_DEPTH,st_type);
	  mc_MachineClose();
	  tc_close_typechecker(0);
	  ct_TranslateClose();
	  break;
	case EMPTY_INPUT:
	  break;
	default:
	  printMsg(FATAL_MSG, "ProcessCmd - Invalid tag (%d)", result->tag);
	  break;
	}
     return(1);
}   /*  end ProcessCmd  */
Example #15
0
void* write_handler(void* socket_desc)
{
    int sock = *(int*)socket_desc;
    int write_size;
    char message[MAX_MESSAGE_LEN];

    /* Get server message and output */
    while(1)
    {
        /* get command and send it to server */
        fgets(message, MAX_MESSAGE_LEN, stdin);
        if(message[0] == '\n')
            continue;
        message_trim(message);
        /* local command */
        if(!strncmp(message, "alias", 5))
        {
            char cmd[MAX_COMMAND_LEN], ali[MAX_COMMAND_LEN];
            if(sscanf(message, "alias %s %s", cmd, ali) == 2)
                addAlias(cmd, ali);
            else
                printf("Format Error: alias <command> <alias>\n");
            continue;
        }

        /* remote command */
        if(mode == MESSAGE_MODE)
        {
            convertAlias(message);
            write_size = write(sock, message, strlen(message));
        }
        if(!(strncmp(message, "download", 8)&&strncmp(message, "dl", 2)))
        {
            /* init trans_state */
            trans_state = TRANSFER_OK;

            /* change to download mode => prevent from invoking other commands */
            mode = DOWNLOAD_MODE;

            /* start sync with rthread */
            pthread_mutex_lock(&wr_mutex);

            /* write filename to server */
            fgets(savedName, MAX_FILENAME_LEN, stdin);
            message_trim(savedName);
            write_size = write(sock, savedName, strlen(savedName));
            /* wait rthread for getting file's size */
            pthread_cond_wait(&fs_cond, &wr_mutex);

            if(trans_state == TRANSFER_OK)
            {
                /* check existance and ask overwrite */
                if(access(savedName, F_OK) != -1)
                {
                    int overwrite = FALSE;

                    /* check overwrite */
                    printf("The file has already existed, do you want to overwrite?[y/n] ");
                    char check;
                    do
                    {
                        scanf("%c", &check);
                        if(check == 'y')
                            overwrite = TRUE;
                    }
                    while(check!='n'&&check!='y');

                    /* send transfer flag to server */
                    if(overwrite)
                    {
                        fp = fopen(savedName, "w");
                        trans_state = TRANSFER_OK;
                        write(sock, "TRANSFER_OK", 11);
                    }
                    else
                    {
                        puts("Download Cancel!");
                        trans_state = TRANSFER_DISCARD;
                        write(sock, "TRANSFER_DISCARD", 16);
                    }

                }
                else
                {
                    fp = fopen(savedName, "w");
                    trans_state = TRANSFER_OK;
                    write(sock, "TRANSFER_OK", 11);
                }
                pthread_cond_signal(&ow_cond);
            }
            // else
            //     printf("DISCARD\n");    // DEBUG - CHECK NOT FILE CONDITION
            pthread_cond_signal(&ow_cond);
 
            /* sync over */
            pthread_mutex_unlock(&wr_mutex);
        }
        else if(!strncmp(message, "put", 3))
        {
            /* change to download mode => prevent from invoking other commands */
            mode = PUT_MODE;

            /* strat sync with wthread */
            pthread_mutex_lock(&wr_mutex);

            printf("File name: \n");
            char filename[MAX_FILENAME_LEN];
            fgets(filename, MAX_FILENAME_LEN-1, stdin);
            message_trim(filename);
            fp = fopen(filename, "r");
            if(fp)
            {
                /* send client file exist flag */
                /* Concat filename and file size then send */
                struct stat st;
                int result = stat(filename, &st);
                long long fsize = st.st_size;
                memset(message, 0, sizeof(message));
                strcpy(message, "FILE_EXIST/");
                strcat(message, filename);
                sprintf(message, "%s/%lld", message, fsize);
                write(sock, message, strlen(message));
                // DEBUG - CHECK INFO MESSAGE
                // printf("%s\n", message);

                /* wait for receiving exist flag */
                pthread_cond_wait(&ow_cond, &wr_mutex);

                // File already exist
                if(trans_state == TRANSFER_WAIT)
                {
                    int overwrite = FALSE;
                    /* check overwrite */
                    printf("The file has already existed, do you want to overwrite?[y/n] ");
                    fflush(stdout);
                    char check;
                    do
                    {
                        scanf("%c", &check);
                        if(check == 'y')
                            overwrite = TRUE;
                    }
                    while(check!='n'&&check!='y');

                    // send overwrite flag
                    if(overwrite)
                    {
                        trans_state = TRANSFER_OK;
                        write(sock, "TRANSFER_OK", 11);
                    }
                    else
                    {
                        trans_state = TRANSFER_DISCARD;
                        write(sock, "TRANSFER_DISCARD", 16);
                        puts("Transfer Cancel!");
                    }

                    pthread_cond_signal(&cf_cond);
                    //  wait READY flag => prevent content being polluted
                    pthread_cond_wait(&rd_cond, &wr_mutex);
                }
                
                // Start transfer
                if(trans_state == TRANSFER_OK)
                {
                    int read_size;
                    while(read_size = fread(message, sizeof(uint8_t), MAX_MESSAGE_LEN-1, fp))
                    {
                        write(sock, message, read_size);  // tranfer data to client until EOF
                    }
                    puts("Transfer Findished!");
                }


                fclose(fp);
                fp = NULL;
            }
            else
            {
                printf("File doesn't exist\n");
                write(sock, "FILE_NOT_EXIST", 14);
            }

            /* strat sync with wthread */
            pthread_mutex_unlock(&wr_mutex);

            /* resume to MESSAGE_MODE */
            mode = MESSAGE_MODE;
        }
    }


    // Free the socket pointer
    free(socket_desc);
}
Example #16
0
 foreach(Alias alias, AliasManager::defaults()) {
     addAlias(alias.name, alias.expansion);
 }
Example #17
0
void runInternal(int m){
int result;
char *promptBuff;
promptBuff = NULL;
	switch(m){
		case 0:
			strcpy(home, getenv("HOME"));
			int i = chdir(home);
			if(i<0) printf("Couldn't restore\n");
			else{
				printf("directory changed\n");
				printf("HOME: %s\n", home);
			}
			exit(0);
		case 1:
			/*if(par[1] != NULL){
					printf("%s is an Unknown command 2\n", *par);
			}
			else{*/
				printf("PATH = %s\n", getenv("PATH"));
				/*}*/
			break;
		case 2:
			if(par[1] == NULL){
					printf("%s is an Unknown command 3\n", *par);
			}
			else{
				int newPath = setenv(par[1], par[1], 0);
				printf("%d", newPath);
				/*const char* path = getenv("PATH");
				printf("PATH :%s\n",(path!=NULL)? path : "getenv returned NULL");*/
			}
			break;
		case 3:
			
			result= 0;
			if(par[1] == NULL){
				chdir("..");
			}
			else{
				result = chdir(par[1]);
				
				if(result == 0){
					printf("\nDirectory changed to %s\n", par[1]);
				}	
				else{
					switch(errno){
					case EACCES: perror("Permission denied");
						break;
					case EIO:	 perror("");
						break;
					case ENAMETOOLONG: perror("");
						break;
					case ENOTDIR: perror(""); 
						break;
					case ENOENT: perror(""); 
      						break;
					}
				}
				
			}
			break;
		case 4:
			printHistory();			
			break;
		case 5: if(par[1] == NULL || par[2] == NULL) {
			printAliases();
		} else {
			addAlias();
		}	
	}	
	
}
Example #18
0
void DiceAliasModel::appendAlias()
{
    addAlias(new DiceAlias(tr("New Alias%1").arg(m_diceAliasList->size()),""));
}
ZLEncodingConverterInfo::ZLEncodingConverterInfo(const std::string &name, const std::string &region) : myName(name), myVisibleName(region + " (" + name + ")") {
	addAlias(myName);
}
Example #20
0
static void
parseLine(const char *line) {
    uint16_t pos=0, start, limit, length, cnv;
    char *converter, *alias;

    /* skip leading white space */
    /* There is no whitespace at the beginning anymore */
/*    while(line[pos]!=0 && isspace(line[pos])) {
        ++pos;
    }
*/

    /* is there nothing on this line? */
    if(line[pos]==0) {
        return;
    }

    /* get the converter name */
    start=pos;
    while(line[pos]!=0 && !isspace((int)line[pos])) {
        ++pos;
    }
    limit=pos;

    /* store the converter name */
    length=(uint16_t)(limit-start);
    converter=allocString(&stringBlock, line+start, length);

    /* add the converter to the converter table */
    cnv=addConverter(converter);

    /* The name itself may be tagged, so let's added it to the aliases list properly */
    pos = start;

    /* get all the real aliases */
    for(;;) {

        /* skip white space */
        while(line[pos]!=0 && isspace((int)line[pos])) {
            ++pos;
        }

        /* is there no more alias name on this line? */
        if(line[pos]==0) {
            break;
        }

        /* get an alias name */
        start=pos;
        while(line[pos]!=0 && line[pos]!='{' && !isspace((int)line[pos])) {
            ++pos;
        }
        limit=pos;

        /* store the alias name */
        length=(uint16_t)(limit-start);
        if (start == 0) {
            /* add the converter as its own alias to the alias table */
            alias = converter;
            addAlias(alias, ALL_TAG_NUM, cnv, TRUE);
        }
        else {
            alias=allocString(&stringBlock, line+start, length);
            addAlias(alias, ALL_TAG_NUM, cnv, FALSE);
        }
        addToKnownAliases(alias);

        /* add the alias/converter pair to the alias table */
        /* addAlias(alias, 0, cnv, FALSE);*/

        /* skip whitespace */
        while (line[pos] && isspace((int)line[pos])) {
            ++pos;
        }

        /* handle tags if they are present */
        if (line[pos] == '{') {
            ++pos;
            do {
                start = pos;
                while (line[pos] && line[pos] != '}' && !isspace((int)line[pos])) {
                    ++pos;
                }
                limit = pos;

                if (start != limit) {
                    /* add the tag to the tag table */
                    uint16_t tag = getTagNumber(line + start, (uint16_t)(limit - start));
                    addAlias(alias, tag, cnv, (UBool)(line[limit-1] == '*'));
                }

                while (line[pos] && isspace((int)line[pos])) {
                    ++pos;
                }
            } while (line[pos] && line[pos] != '}');

            if (line[pos] == '}') {
                ++pos;
            } else {
                fprintf(stderr, "%s:%d: Unterminated tag list\n", path, lineNum);
                exit(U_UNMATCHED_BRACES);
            }
        } else {
            addAlias(alias, EMPTY_TAG_NUM, cnv, (UBool)(tags[0].aliasList[cnv].aliasCount == 0));
        }
    }
}