Obj FuncCREATE_PTY_IOSTREAM( Obj self, Obj dir, Obj prog, Obj args ) { Obj allargs[MAX_ARGS+1]; Char *argv[MAX_ARGS+2]; UInt i,len; Int pty; len = LEN_LIST(args); if (len > MAX_ARGS) ErrorQuit("Too many arguments",0,0); ConvString(dir); ConvString(prog); for (i = 1; i <=len; i++) { allargs[i] = ELM_LIST(args,i); ConvString(allargs[i]); } /* From here we cannot afford to have a garbage collection */ argv[0] = CSTR_STRING(prog); for (i = 1; i <=len; i++) { argv[i] = CSTR_STRING(allargs[i]); } argv[i] = (Char *)0; pty = StartChildProcess( CSTR_STRING(dir) , CSTR_STRING(prog), argv ); if (pty < 0) return Fail; else return INTOBJ_INT(pty); }
Obj MPIrecv( Obj self, Obj args ) { volatile Obj buf, source, tag; /* volatile to satisfy gcc compiler */ MPIARGCHK( 1, 3, MPI_Recv( <string buf>, <opt int source = MPI_ANY_SOURCE>[, <opt int tag = MPI_ANY_TAG> ] ) ); buf = ELM_LIST( args, 1 ); source = ( LEN_LIST(args) > 1 ? ELM_LIST( args, 2 ) : INTOBJ_INT(MPI_ANY_SOURCE) ); tag = ( LEN_LIST(args) > 2 ? ELM_LIST( args, 3 ) : INTOBJ_INT(MPI_ANY_TAG) ); if ( ! IS_STRING( buf ) ) ErrorQuit("MPI_Recv(): received a buffer that is not a string", 0L, 0L); ConvString( buf ); /* Note GET_LEN_STRING() returns GAP string length and strlen(CSTR_STRING()) returns C string length (up to '\0') */ if ( ! MPI_READ_ERROR() ) MPI_Recv( CSTR_STRING(buf), GET_LEN_STRING(buf), last_datatype=MPIdatatype_infer(buf), INT_INTOBJ(source), INT_INTOBJ(tag), MPI_COMM_WORLD, &last_status); MPI_READ_DONE(); if ( ! IS_STRING( buf ) ) { /* CLEAN THIS UP LATER */ ErrorQuit("ParGAP: panic: MPI_Recv(): result buffer is not a string", 0L, 0L); exit(1); } /* if (last_datatype != MPI_CHAR) { MPI_Get_count(&last_status, last_datatype, &count); etc. } */ return buf; }
Obj FuncWRITE_IOSTREAM( Obj self, Obj stream, Obj string, Obj len ) { UInt pty = INT_INTOBJ(stream); ConvString(string); while (!PtyIOStreams[pty].inuse) pty = INT_INTOBJ(ErrorReturnObj("IOSTREAM %d is not in use",pty,0L, "you can replace stream number <num> via 'return <num>;'")); HandleChildStatusChanges(pty); return INTOBJ_INT(WriteToPty(pty, CSTR_STRING(string), INT_INTOBJ(len))); }
Obj UNIX_Chdir( Obj self, Obj string ) { int result; ConvString( string ); result = chdir( (char*)CSTR_STRING(string) ); if (result == -1) { fprintf( stderr, "UNIX_Chdir: %s\n", (char*)CSTR_STRING(string) ); perror("UNIX_Chdir"); } return ( 0 == result ? True : False ) ; }
Obj MPIsend( Obj self, Obj args ) { Obj buf, dest, tag; MPIARGCHK(2, 3, MPI_Send( <string buf>, <int dest>[, <opt int tag = 0> ] )); buf = ELM_LIST( args, 1 ); dest = ELM_LIST( args, 2 ); tag = ( LEN_LIST(args) > 2 ? ELM_LIST( args, 3 ) : 0 ); ConvString( buf ); MPI_Send( ((char*)CSTR_STRING(buf)), strlen((const Char*)CSTR_STRING(buf)), /* don't incl. \0 */ MPIdatatype_infer(buf), INT_INTOBJ(dest), INT_INTOBJ(tag), MPI_COMM_WORLD); return 0; }
Obj MPIrecv2( Obj self, Obj args ) { volatile Obj buf, source, tag; /* volatile to satisfy gcc compiler */ int count, sranje; MPI_Comm_rank(MPI_COMM_WORLD, &sranje); MPIARGCHK( 0, 2, MPI_Recv( <opt int source = MPI_ANY_SOURCE>[, <opt int tag = MPI_ANY_TAG> ] ) ); source = ( LEN_LIST(args) > 0 ? ELM_LIST( args, 1 ) : INTOBJ_INT(MPI_ANY_SOURCE) ); tag = ( LEN_LIST(args) > 1 ? ELM_LIST( args, 2 ) : INTOBJ_INT(MPI_ANY_TAG) ); MPI_Probe(INT_INTOBJ(source), INT_INTOBJ(tag), MPI_COMM_WORLD, &last_status); MPI_Get_count(&last_status, MPI_CHAR, &count); buf = NEW_STRING( count); ConvString( buf ); /* Note GET_LEN_STRING() returns GAP string length and strlen(CSTR_STRING()) returns C string length (up to '\0') */ MPI_Recv( CSTR_STRING(buf), GET_LEN_STRING(buf), MPI_CHAR, INT_INTOBJ(source), INT_INTOBJ(tag), MPI_COMM_WORLD, &last_status); MPI_READ_DONE(); /* if (last_datatype != MPI_CHAR) { MPI_Get_count(&last_status, last_datatype, &count); etc. } */ return buf; }
int wmain( int argc, wchar_t *argv[] ) { int i ; wchar_t *FontName = NULL ; int FontSize = -1 ; int FontThickness = -1 ; int FontBitDepth = DX_FONTIMAGE_BIT_8 ; int FontItalic = FALSE ; int FontCharSet = -1 ; wchar_t *FontSaveCharaListFilePath = NULL ; wchar_t *SaveFilePath = NULL ; wchar_t *SaveCharaList = NULL ; setlocale( LC_ALL, "Japanese" ) ; wprintf( L"DXフォントデータファイル作成ソフト Ver0.1 Yamada Takumi\n" ) ; for( i = 1; i < argc; i ++ ) { if( wcsncmp( argv[ i ], L"-?", 2 ) == 0 || wcsncmp( argv[ i ], L"/?", 2 ) == 0 ) { wprintf( L"CreateDXFontData [/?][/Fフォント名][/Sサイズ][/T太さ][/Bビット数][/I][/C文字セット][/Aテキストファイルパス][/Oフォントデータファイルパス]\n" ) ; wprintf( L" /? ヘルプ\n" ) ; wprintf( L" /F フォント名\n" ) ; wprintf( L" /S サイズ\n" ) ; wprintf( L" /T 太さ\n" ) ; wprintf( L" /B 1ピクセルのビット数( 1 or 4 or 8 )\n" ) ; wprintf( L" /I イタリックにします\n" ) ; wprintf( L" /C 文字セット\n" ) ; wprintf( L" DEFAULT デフォルト文字\n" ) ; wprintf( L" SHIFTJIS シフトJIS文字\n" ) ; wprintf( L" HANGEUL ハングル文字\n" ) ; wprintf( L" BIG5 繁体文字\n" ) ; wprintf( L" GB2312 簡体文字\n" ) ; wprintf( L" /A DXフォントデータファイルに含める文字の一覧が載ったテキストファイルのパスの指定、対応形式は「シフトJIS(メモ帳では「ANSI」)」「UTF-16LE(メモ帳では「Unicode」)」の2種類です\n" ) ; wprintf( L" /O DXフォントデータファイルの保存ファイルパス\n" ) ; return 0 ; } else if( wcsncmp( argv[ i ], L"-F", 2 ) == 0 || wcsncmp( argv[ i ], L"/F", 2 ) == 0 ) { FontName = argv[ i ] + 2 ; } else if( wcsncmp( argv[ i ], L"-S", 2 ) == 0 || wcsncmp( argv[ i ], L"/S", 2 ) == 0 ) { FontSize = CL_atoi( CODEPAGE_UTF16LE, ( char * )argv[ i ] + 2 ) ; } else if( wcsncmp( argv[ i ], L"-T", 2 ) == 0 || wcsncmp( argv[ i ], L"/T", 2 ) == 0 ) { FontThickness = CL_atoi( CODEPAGE_UTF16LE, ( char * )argv[ i ] + 2 ) ; } else if( wcsncmp( argv[ i ], L"-B", 2 ) == 0 || wcsncmp( argv[ i ], L"/B", 2 ) == 0 ) { switch( CL_atoi( CODEPAGE_UTF16LE, ( char * )argv[ i ] + 2 ) ) { default : case 1 : FontBitDepth = DX_FONTIMAGE_BIT_1 ; break ; case 4 : FontBitDepth = DX_FONTIMAGE_BIT_4 ; break ; case 8 : FontBitDepth = DX_FONTIMAGE_BIT_8 ; break ; } } else if( wcsncmp( argv[ i ], L"-I", 2 ) == 0 || wcsncmp( argv[ i ], L"/I", 2 ) == 0 ) { FontItalic = TRUE; } else if( wcsncmp( argv[ i ], L"-C", 2 ) == 0 || wcsncmp( argv[ i ], L"/C", 2 ) == 0 ) { if( wcscmp( argv[ i ] + 2, L"DEFAULT" ) == 0 ) { FontCharSet = DX_CHARSET_DEFAULT ; } else if( wcscmp( argv[ i ] + 2, L"SHIFTJIS" ) == 0 ) { FontCharSet = DX_CHARSET_SHFTJIS ; } else if( wcscmp( argv[ i ] + 2, L"HANGEUL" ) == 0 ) { FontCharSet = DX_CHARSET_HANGEUL ; } else if( wcscmp( argv[ i ] + 2, L"BIG5" ) == 0 ) { FontCharSet = DX_CHARSET_BIG5 ; } else if( wcscmp( argv[ i ] + 2, L"GB2312" ) == 0 ) { FontCharSet = DX_CHARSET_GB2312 ; } } else if( wcsncmp( argv[ i ], L"-A", 2 ) == 0 || wcsncmp( argv[ i ], L"/A", 2 ) == 0 ) { FontSaveCharaListFilePath = argv[ i ] + 2 ; } else if( wcsncmp( argv[ i ], L"-O", 2 ) == 0 || wcsncmp( argv[ i ], L"/O", 2 ) == 0 ) { SaveFilePath = argv[ i ] + 2 ; } } if( SaveFilePath == NULL ) { SaveFilePath = L"FontData.dft" ; } if( FontSaveCharaListFilePath != NULL ) { FILE *fp ; long FileSize ; BYTE *FileBuffer = NULL ; fp = _wfopen( FontSaveCharaListFilePath, L"rb" ) ; if( fp != NULL ) { fseek( fp, 0, SEEK_END ) ; FileSize = ftell( fp ) ; fseek( fp, 0, SEEK_SET ) ; FileBuffer = ( BYTE * )malloc( FileSize + 16 ) ; memset( FileBuffer, 0, FileSize + 16 ) ; if( FileBuffer != NULL ) { fread( FileBuffer, FileSize, 1, fp ) ; if( FileBuffer[ 0 ] == 0xff && FileBuffer[ 1 ] == 0xfe ) { SaveCharaList = ( wchar_t * )malloc( sizeof( wchar_t ) * ( FileSize / 2 + 16 ) ) ; memset( SaveCharaList, 0, sizeof( wchar_t ) * ( FileSize / 2 + 16 ) ) ; memcpy( SaveCharaList, FileBuffer + 2, FileSize - 2 ) ; } else { SaveCharaList = ( wchar_t * )malloc( sizeof( wchar_t ) * ( FileSize + 1 ) ) ; memset( SaveCharaList, 0, sizeof( wchar_t ) * ( FileSize + 1 ) ) ; ConvString( ( const char * )FileBuffer, CODEPAGE_SHIFTJIS, ( char * )SaveCharaList, CODEPAGE_UTF16LE ) ; } free( FileBuffer ) ; } fclose( fp ) ; } } InitializeFont() ; CreateFontDataFile( SaveFilePath, FontName, FontSize, FontBitDepth, FontThickness, FontItalic, FontCharSet, -1, SaveCharaList ) ; if( SaveCharaList != NULL ) { free( SaveCharaList ) ; SaveCharaList = NULL ; } return 0; }