Example #1
0
int ReadOtherSubrsFile(char *filename) {
    FILE *os = fopen(filename,"r");
    char buffer[500];
    char **lines=NULL;
    int l=0, lmax=0;
    int sub_num = -1;
    const char **co=NULL, **osubs[14];
    int i;

    if ( os==NULL )
return( false );
    while ( fgets(buffer,sizeof(buffer),os)!=NULL ) {
	int len = strlen(buffer);
	if ( len>0 && (buffer[len-1]=='\r' || buffer[len-1]=='\n')) {
	    if ( len>1 && (buffer[len-2]=='\r' || buffer[len-2]=='\n'))
		buffer[len-2] = '\0';
	    else
		buffer[len-1] = '\0';
	}
	if ( buffer[0]=='%' && buffer[1]=='%' && buffer[2]=='%' && buffer[3]=='%' ) {
	    if ( sub_num == -1 )
		co = CopyLines(lines,l,true);
	    else if ( sub_num<14 )
		osubs[sub_num] = CopyLines(lines,l,false);
	    else if ( sub_num==14 )
		LogError( _("Too many subroutines. We can deal with at most 14 (0-13)\n") );
	    ++sub_num;
	    l = 0;
	} else {
	    if ( l>=lmax ) {
		lmax += 100;
		lines = realloc(lines,lmax*sizeof(char *));
	    }
	    lines[l++] = copy(buffer);
	}
    }
    fclose( os );
    /* we just read a copyright notice? That's no use */
    if ( sub_num<=0 )
return( false );
    while ( sub_num<14 ) {
	osubs[sub_num] = calloc(2,sizeof(char *));
	osubs[sub_num][0] = copy("{}");
	++sub_num;
    }
    DefaultOtherSubrs();
    othersubrs_copyright[0] = co;
    for ( i=0; i<14; ++i )
	othersubrs[i] = osubs[i];
    free(lines);
return( true );
}
Example #2
0
VOID
GuiCopyFromTextModeBuffer(PTEXTMODE_SCREEN_BUFFER Buffer,
                          PGUI_CONSOLE_DATA GuiData)
{
    /*
     * This function supposes that the system clipboard was opened.
     */

    BOOL LineSelection = GuiData->LineSelection;

    DPRINT("Selection is (%d|%d) to (%d|%d) in %s mode\n",
           GuiData->Selection.srSelection.Left,
           GuiData->Selection.srSelection.Top,
           GuiData->Selection.srSelection.Right,
           GuiData->Selection.srSelection.Bottom,
           (LineSelection ? "line" : "block"));

    if (!LineSelection)
    {
        CopyBlock(Buffer, &GuiData->Selection.srSelection);
    }
    else
    {
        COORD Begin, End;

        GetSelectionBeginEnd(&Begin, &End,
                             &GuiData->Selection.dwSelectionAnchor,
                             &GuiData->Selection.srSelection);

        CopyLines(Buffer, &Begin, &End);
    }
}