Exemplo n.º 1
0
void    IOErr( int errcode, ... ) {
//=================================

// Handle a run time i/o error.

    char        errbuff[ERR_BUFF_SIZE+1];
    va_list     args;

    va_start( args, errcode );
        if( ( IOCB->set_flags & (SET_IOSPTR|SET_ERRSTMT) ) == 0 ) {
            if( errcode == IO_FILE_PROBLEM ) {
                GetIOErrMsg( IOCB->fileinfo, errbuff );
                SysIOErr( errcode, errbuff );
            } else {
                ErrHandler( errcode, args );
            }
        } else {
            errcode = ErrCodOrg( errcode );
            if( IOCB->fileinfo != NULL ) {
                IOCB->fileinfo->error = errcode;
            }
            IOCB->status = errcode;
        }
        Suicide();
    va_end( args );
}
/****
* Retrieve the currently selected file and display it in the configured
* editor.
****/
static void
get_selected_file(HWND hDlg, int command_id)
{
	int index;
	char szBuf[MAXPATHLEN];

	/* get currently selected item */
	index = (int)SendDlgItemMessage(hDlg, IDC_MAIN_LISTBOX,
		LB_GETCURSEL, 0, 0L);
	if(index == LB_ERR && command_id == IDC_MAIN_EDIT)
	{
		ErrHandler(hDlg, R_WARNING, RB_OK1, "Nothing selected. Please "
			"select a file from the list");
		return;
	}

	/* empty listbox */
	if(index == LB_ERR)
		return;

	/* get name of selected file */
	SendDlgItemMessage(hDlg, IDC_MAIN_LISTBOX, LB_GETTEXT, index, 
		(LONG)(LPSTR)szBuf);
	switch(command_id)
	{
		case IDC_MAIN_EDIT:
		case IDC_MAIN_LISTBOX:
			edit_file(szBuf, 0);
			break;
		case IDC_MAIN_REMOVE:
			file_sel_changed = 1;
			SendDlgItemMessage(hDlg, IDC_MAIN_LISTBOX,
				LB_DELETESTRING, index, 0L);
	}
}
/*****
* Retrieve all items from the file listbox in the main window.
* This routine discards any preloaded list of files.
* As a consequence of that, it also discards any flowgraph generated from 
* that filelist.
*
* Returns 0 if there are no files else returns 1.
*****/
static int
get_files_to_scan(HWND hDlg)
{
	int i;
	char szBuf[MAXPATHLEN];
	HWND hwndList = GetDlgItem(hDlg, IDC_MAIN_LISTBOX);

	if(num_files != 0 && !file_sel_changed)
		return(1);
	/* clear previous list */
	destroy_filelist();

	/* get no of items in the list */
	num_files = (int)SendMessage(hwndList, LB_GETCOUNT, 0, 0L);

	/* return if no files in list */
	if(num_files == 0)
		return(0);

	/* allocate memory for this list */
	file_list = (char**)GlobalAllocPtr(GPTR, (num_files+1)*sizeof(char*));
	if(file_list == NULL)
	{
		ErrHandler(hDlg, R_ERROR, RB_OK1, "Out of memory: Failed to "
			"allocate %i bytes for filelist",
			num_files*sizeof(char*));
		exit(4);
	}
	/* get the items in the list */
	for(i = 0; i < num_files; i++)
	{
		SendMessage(hwndList, LB_GETTEXT, i, (LONG)(LPSTR)szBuf);
		file_list[i]=(char*)GlobalAllocPtr(GPTR,
			(strlen(szBuf)+1)*sizeof(char));
		if(file_list[i] == NULL)
		{
			ErrHandler(hDlg, R_ERROR, RB_OK1, "Out of memory: "
				"Failed to allocate %i bytes for file %i",
				(strlen(szBuf)+1)*sizeof(char), szBuf);
			exit(4);
		}
		strcpy(file_list[i], szBuf);
	}
	file_sel_changed = 0;
	return(1);
}
Exemplo n.º 4
0
void init_timer(void){
memset (&sa_in_message, 0, sizeof (sa_in_message));
sa_in_message.sa_handler = timer_handler;
if((sigaction(SIGALRM, &sa_in_message, NULL))== -1){
    err_num = SASET_ERR;
    ErrHandler();
    return;
  }
}
Exemplo n.º 5
0
static  void    SysIOErr( int errcode, ... ) {
//============================================

    va_list     args;

    va_start( args, errcode );
    ErrHandler( errcode, args );
    va_end( args );
}
Exemplo n.º 6
0
void set_timer(struct timeval time_interval){
    timer.it_value = time_interval;
    timer.it_interval.tv_sec = 0;
    timer.it_interval.tv_usec = 0;
    if((setitimer (ITIMER_REAL, &timer, NULL)) == -1){
       err_num = SETITIMER_ERR;
       ErrHandler();
       return;
    }
}
Exemplo n.º 7
0
int list_add_in(list_ptr_t *list, TIME_PROTOCOL duration,  DADDRESS address){
    struct timeval time_interval;
    pthread_mutex_lock(&mutex_list_in);
    if((list_put(list, address, time(NULL) + duration, duration,NULL)) == NULL){
        err_num = PUT_IN_ERR;
        ErrHandler();
        return 1;
    }
    pthread_mutex_unlock(&mutex_list_in);
    time_interval.tv_sec = ((*list)->data)->duration;
    time_interval.tv_usec = 0;
    set_timer(time_interval);
    return 0;
}
Exemplo n.º 8
0
int list_device_sleep(list_ptr_t list, DADDRESS address, TIME_PROTOCOL duration){

    struct timeval time_interval;
    list_ptr_t temp;
     pthread_mutex_lock(&mutex_list_in);
     list_get_by_address(list,address,&temp);
     if(temp == NULL){
         err_num = DEVICE_NOTCONNECT_ERR;
         ErrHandler();
         return 1;
     }
    pthread_mutex_unlock(&mutex_list_in);
    temp->data->duration = duration;
    pthread_mutex_lock(&mutex_list_in);
    list_update(&list,address,time(NULL)+duration);
    pthread_mutex_unlock(&mutex_list_in);
    time_interval.tv_sec = (list->data)->duration;
    time_interval.tv_usec = 0;
    set_timer(time_interval);

    return 0;
}
/*****
* This routine scans the editor command entered or loaded
* and composes a string used composing the WinExec command line.
*
* The user can enter a editor command of the form:
* <editor> @FILE <options> @LINE
* where @FILE is the name of the file to edit, and
* @LINE is the linenumber where the editor should start.
*
* This routine sets a global variable editor_order which can have the
* following values (where %s indicates FILE and %i indicates LINE):
*
* Value		Command			has_file_cmd	has_line_cmd
* ------------------------------------------------------------------
* 1		<editor> %s		1 or 0		0
* 2		<editor> %s %i		1		2
* 3		<editor> %i %s		2 or 0		1
*****/
static void
parse_editor_command(char *string)
{
	char *outPtr = string;
	short has_file_cmd = 0;
	short has_line_cmd = 0;
	short i;
	char szBuf[MAXPATHLEN];

	/* clear buffer */
	memset(szBuf, '\0', MAXPATHLEN);

	for(i = 0, outPtr; *outPtr != '\0'; outPtr++, i++)
	{
		switch(*outPtr)
		{
			case '@':
				outPtr++;
				if(!strncmpi(outPtr, "file", 4))
				{
					/* outPtr also gets incremented above */
				   	outPtr += 3;
					if(!has_line_cmd)
						has_file_cmd = 1;
					else
						has_file_cmd = 2;
					strcat(szBuf, "%s");
					i += 1;	
				}
				else
				{
					if(!strncmpi(outPtr, "line", 4))
					{
						outPtr += 3;
						if(!has_file_cmd)
							has_line_cmd = 1;
						else
							has_line_cmd = 2;
						strcat(szBuf, "%i");
						i+=1;
					}
					else
					{
						ErrHandler(NULL, R_MESSAGE, 
							RB_OK1, "Unknown editor"
							" variable %s detected,"
							" ignoring\n", outPtr);
						for(; *outPtr != '\0' && 
							*outPtr != ' '; 
							outPtr++, i++);
					}
				}
				break;
			default:
				szBuf[i] = *outPtr;
		}
	}
	szBuf[i] = '\0';
	/* file = 0, line = 0, see table above */
	if(!has_file_cmd && !has_line_cmd)
	{
		has_file_cmd = 1;	/* file comes first */
		strcat(szBuf, " %s");
	}
	/* file = 0, line = 1, see table above */
	if(!has_file_cmd && has_line_cmd)
	{
		editor_order = 3;	/* file comes last */
		strcat(szBuf, " %s");
		has_file_cmd = 2;
	}

	if(has_file_cmd == 1 && has_line_cmd == 2)
		editor_order = 2;
	if(has_file_cmd == 2 && has_line_cmd == 1)
		editor_order = 3;
	if(has_file_cmd == 1 && has_line_cmd == 0)
		editor_order = 1;

	strncpy(default_editor, szBuf, strlen(szBuf));
	default_editor[strlen(szBuf)] = '\0';
}
Exemplo n.º 10
0
void CMatlabEngine::GetLastErrorMessage() const
{
	if(FAILED(m_hr))
		ErrHandler(m_hr, m_excep, m_uArgErr);
}
/*****
* Main window dialog box procedure
*****/
long FAR PASCAL _export
WndProc(HWND hwnd, UINT message, UINT wParam, LONG lParam)
{
	HBRUSH hbrush;

	switch (message)
	{
		case WM_CREATE:
			file_sel_changed = 0;
			/* attach keyboard interface */
			if((myhookproc = SetWindowsHookEx(WH_KEYBOARD,
				(HOOKPROC)KeyboardProc, hInst,
				GetCurrentTask())) == NULL)
				ErrHandler(NULL, R_ERROR, RB_OK1, "Winfflow "
					"Error: failed to set keyboard hook.\n"
					"Keyboard interface not installed.");
			return FALSE;
		/* following four cases ctl3d specific */
		case WM_SYSCOLORCHANGE:
			Ctl3dColorChange();
			return FALSE;
		case WM_SETTEXT:
		case WM_NCPAINT:
		case WM_NCACTIVATE:
			SetWindowLong(hwnd, DWL_MSGRESULT,
				Ctl3dDlgFramePaint(hwnd, message, wParam, 
				lParam));
			return TRUE;
		/*
		* paint window background with a brush provided by the response
		* to the WM_CTLCOLOR message
		*/
		case WM_ERASEBKGND:
		{
			RECT lprc;
			HDC hdc = (HDC)wParam;

			if(hwnd != hWndMain)
				return TRUE;
			if(!background_brush)
				return TRUE;
			UnrealizeObject(background_brush);
			GetClientRect(hwnd, &lprc);
			SetBrushOrg(hdc, 0, 0);
			SelectObject(hdc, background_brush);
			FillRect(hdc, &lprc, background_brush);
			return TRUE;
		}
		case WM_SIZE:
			switch(wParam)
			{
				case SIZE_MAXIMIZED:
				case SIZE_RESTORED:
					if(!block_resize)
						DoResize(hwnd, 0);
					return FALSE;
				default:
					break;
			}
			break;
		case WM_COMMAND:
		switch(GET_COMMAND_ID)
		{
			case IDC_MAIN_ABOUT:
				DisplayDialog(hwnd, hInst,WINFFLOW_ABOUT_DIALOG,
					AboutProc);
				break;
			/* add files to the listbox */
			case IDC_MAIN_ADD:
				get_fortran_files(hwnd);
				break;

			/* double click will edit selected file */
			case IDC_MAIN_LISTBOX:
				if(GET_COMMAND_CMD == LBN_DBLCLK)
					get_selected_file(hwnd, 
						IDC_MAIN_LISTBOX);
				break;

			/* remove/edit selected file */
			case IDC_MAIN_EDIT:
			case IDC_MAIN_REMOVE:
				get_selected_file(hwnd, GET_COMMAND_ID);
				break;
			case IDC_MAIN_REMOVE_ALL:
				SendDlgItemMessage(hwnd, IDC_MAIN_LISTBOX, 
					LB_RESETCONTENT, 0, 0L);
				destroy_filelist();
				break;
			/* settings */
			case IDC_MAIN_SETTINGS:
				DisplayDialog(hwnd, hInst,
					WINFFLOW_SETTINGS_DIALOG,
					(FARPROC)SettingsProc);
				break;

			/* scan the files */
			case IDOK:
				/*
				* scan the files when the selection has changed,
				* there is no current flowgraph or when the 
				* previous scan has been aborted
				*/
				if(file_sel_changed || flow == NULL ||
					yylex_abort)
				{
					/* pick up files */
					if(!get_files_to_scan(hwnd))
						break;
					generate_flowgraph();
				}
				/* hide main window */
				ShowWindow(hWndMain, SW_HIDE);
				/* display selector dialog box */
				DisplayDialog(hwnd, hInst,
					WINFFLOW_OUTPUTSELECTOR_DIALOG,
					(FARPROC)SelectorProc);
				/* display main window again */
				ShowWindow(hWndMain, SW_RESTORE);
				break;
			case IDCANCEL:
				/* save the filelist */
				save_ini_file_data(hwnd);
				SendMessage(hWndMain, WM_CLOSE, 0, 0L);
				break;
			case IDHELP:
				WinHelp(hWndMain, "winfflow.hlp", 
					HELP_CONTEXT, WINFFLOW_MAIN_DIALOG);
				break;
		} return(FALSE);
		case WM_SYSCOMMAND:
			if(GET_COMMAND_ID == SC_CLOSE)	/* Get the close item */
			{
				SendMessage(hWndMain, WM_CLOSE, 0, 0L);
				return FALSE;
			}
			break;
		case WM_CLOSE:
			UnregisterResize(hwnd);
			DestroyWindow(hwnd);
			return FALSE;
		case WM_DESTROY:
			PostQuitMessage (0) ;
			return FALSE;
/* Ctl3d specific code */
#ifdef WIN32
		case WM_CTLCOLORBTN:
		case WM_CTLCOLORDLG:
		case WM_CTLCOLOREDIT:
		case WM_CTLCOLORLISTBOX:
		case WM_CTLCOLORMSGBOX:
		case WM_CTLCOLORSCROLLBAR:
		case WM_CTLCOLORSTATIC:
#else
		case WM_CTLCOLOR:
#endif
			hbrush = Ctl3dCtlColorEx(message, wParam, lParam);
			if (hbrush != (HBRUSH) FALSE)
			{
				/* save this brush */
				background_brush = hbrush;
				return hbrush;
			}
			/* fall through */
		default:
			break;
	 }
	 return (DefWindowProc (hwnd, message, wParam, lParam));
}
/*****
* Display a file selection dialog box to allow the
* user to select files he wishes to scan
*****/
static void
get_fortran_files(HWND hDlg)
{
	OPENFILENAME ofn;
	char szDirName[128];
	static char szFile[1024];
	UINT  i, cbString;
	char  chReplace;	/* string separator for szFilter */
	char  szFilter[256];
	i = 0;

	/* clear szFile buffer */
	memset(szFile, '\0', 1024);

	/* initial directory appearing in the fileselectiondialog. */
	strcpy(szDirName, initial_dir);

	/*
	* Load string needed for the possible filters used by the fileselection
	* dialog.
	*/
	memset(szFilter, '\0', sizeof(szFilter));
	if ((cbString = LoadString(hInst, IDS_FILTERSTRING, szFilter,
		sizeof(szFilter))) == 0)
	{
		ErrHandler(hDlg, R_ERROR, RB_OK1, "Internal Error: failed to "
			"get resource");
		return;
	}
	/* retrieve filter wildcard */
	chReplace = szFilter[cbString - 1];
	for (i = 0; szFilter[i] != '\0'; i++)
	{
		if (szFilter[i] == chReplace)
		szFilter[i] = '\0';
	}

	/* Set all structure members to zero. */
	memset(&ofn, 0, sizeof(OPENFILENAME));
	/* Fill appropriate fields */
	ofn.lStructSize = sizeof(OPENFILENAME);
	ofn.hwndOwner = hDlg;
	/* filter string */
	ofn.lpstrFilter = szFilter;
	/* default filter to use */
	ofn.nFilterIndex = 1;
	/* this string will contain selected files upon return */
	ofn.lpstrFile= szFile;
	ofn.nMaxFile = sizeof(szFile);
	/* initial directory to use */
	ofn.lpstrInitialDir = szDirName;
	/* title for this fileselection dialog box */
	ofn.lpstrTitle = "Select Files to Scan";
	/* fileselection dialog configuration flags */
	ofn.Flags = OFN_PATHMUSTEXIST|OFN_FILEMUSTEXIST|OFN_ALLOWMULTISELECT;

	/* display fileselection dialog box */
	if(GetOpenFileName(&ofn))
	{
		/* zero out initial_dir */
		memset(initial_dir, '\0', sizeof(initial_dir));
		/* save original dir.*/
		strncpy(initial_dir, ofn.lpstrFile, ofn.nFileOffset);
		/* cut off a trailing slash */
		if(initial_dir[strlen(initial_dir) - 1] == '\\')
			initial_dir[strlen(initial_dir) - 1] = '\0';
		/* remove trailing spaces, if any */
		stripspaces(initial_dir);
		/* make it lower case */
		downcase(initial_dir);
		/* file the file listbox in the main window */
		fill_file_listbox(hDlg, ofn.lpstrFile, ofn.nFileOffset,
			initial_dir);
	}
}