/******************************************************************************* Copyright by Telesoft Europe AB 1990, 1991. Copyright by Telelogic Malmoe AB 1991, 1992, 1993, 1994. Copyright by Telelogic AB 1994 - 2001. This Program is owned by Telelogic and is protected by national copyright laws and international copyright treaties. Telelogic grants you the right to use this Program on one computer or in one local computer network at any one time. Under this License you may only modify the source code for the purpose of adapting it to your environment. You must reproduce and include any copyright and trademark notices on all copies of the source code. You may not use, copy, merge, modify or transfer the Program except as provided in this License. Telelogic does not warrant that the Program will meet your requirements or that the operation of the Program will be uninterrupted and error free. You are solely responsible that the selection of the Program and the modification of the source code will achieve your intended results and that the results are actually obtained. *******************************************************************************/ SYNTYPE FileName = Charstring ENDSYNTYPE; SYNONYM NULL /*#NAME 'NULL2' */ FileName = 'NULL'; SYNONYM stdin /*#NAME 'stdin2' */ FileName = 'stdin'; SYNONYM stdout /*#NAME 'stdout2' */ FileName = 'stdout'; SYNONYM stderr /*#NAME 'stderr2' */ FileName = 'stderr'; NEWTYPE TextFile /*#NAME 'TextFile' */ LITERALS NULL /*#NAME 'TextFileNull' */, /*#OP(S)*/ stdin /*#NAME 'stdin1' */, /*#OP(S)*/ stdout /*#NAME 'stdout1' */, /*#OP(S)*/ stderr /*#NAME 'stderr1' */; /*#OP(S)*/ OPERATORS GetAndOpenR /*#NAME 'GetAndOpenR' */ : FileName -> TextFile; GetAndOpenW /*#NAME 'GetAndOpenW' */ : FileName -> TextFile; OpenR /*#NAME 'OpenR' */ : FileName -> TextFile; OpenW /*#NAME 'OpenW' */ : FileName -> TextFile; OpenA /*#NAME 'OpenA' */ : FileName -> TextFile; Close /*#NAME 'Close' */ : TextFile -> TextFile; Flush /*#NAME 'Flush' */ : TextFile -> TextFile; IsOpened /*#NAME 'IsOpened' */ : TextFile -> Boolean; AtEOF /*#NAME 'AtEOF' */ : TextFile -> Boolean; AtLastChar /*#NAME 'AtLastChar' */ : TextFile -> Boolean; PutReal /*#NAME 'PutReal' */ : TextFile, Real -> TextFile; PutTime /*#NAME 'PutTime' */ : TextFile, Time -> TextFile; PutDuration /*#NAME 'PutDuration' */ : TextFile, Duration -> TextFile; PutPid /*#NAME 'PutPid' */ : TextFile, Pid -> TextFile; PutInteger /*#NAME 'PutInteger' */ : TextFile, Integer -> TextFile; PutBoolean /*#NAME 'PutBoolean' */ : TextFile, Boolean -> TextFile; PutCharacter /*#NAME 'PutCharacter' */ : TextFile, Character -> TextFile; PutCharstring /*#NAME 'PutCharstring' */ : TextFile, Charstring -> TextFile; PutString /*#NAME 'PutString' */ : TextFile, Charstring -> TextFile; PutLine /*#NAME 'PutLine' */ : TextFile, Charstring -> TextFile; PutNewLine /*#NAME 'PutNewLine' */ : TextFile -> TextFile; "//" /*#NAME 'PutReal' */ : TextFile, Real -> TextFile; "//" /*#NAME 'PutTime' */ : TextFile, Time -> TextFile; "//" /*#NAME 'PutDuration' */ : TextFile, Duration -> TextFile; "//" /*#NAME 'PutInteger' */ : TextFile, Integer -> TextFile; "//" /*#NAME 'PutBoolean' */ : TextFile, Boolean -> TextFile; "+" /*#NAME 'PutCharacter' */ : TextFile, Character -> TextFile; "//" /*#NAME 'PutString' */ : TextFile, Charstring -> TextFile; "//" /*#NAME 'Pid' */ : TextFile, Pid -> TextFile; GetReal /*#NAME 'GetReal' */ : TextFile, Charstring -> Real; GetTime /*#NAME 'GetTime' */ : TextFile, Charstring -> Time; GetDuration /*#NAME 'GetDuration' */ : TextFile, Charstring -> Duration; GetPid /*#NAME 'GetPid' */ : TextFile, Charstring -> Pid; GetInteger /*#NAME 'GetInteger' */ : TextFile, Charstring -> Integer; GetBoolean /*#NAME 'GetBoolean' */ : TextFile, Charstring -> Boolean; GetCharacter /*#NAME 'GetCharacter' */ : TextFile, Charstring -> Character; GetCharstring /*#NAME 'GetCharstring' */ : TextFile, Charstring -> Charstring; GetString /*#NAME 'GetString' */ : TextFile, Charstring -> Charstring; GetLine /*#NAME 'GetLine' */ : TextFile, Charstring -> Charstring; GetSeed /*#NAME 'GetSeed' */ : TextFile, Charstring -> Integer; GetReal /*#NAME 'GetR' */ : TextFile -> Real; GetDuration /*#NAME 'GetD' */ : TextFile -> Duration; GetTime /*#NAME 'GetT' */ : TextFile -> Time; GetPid /*#NAME 'GetP' */ : TextFile -> Pid; GetInteger /*#NAME 'GetI' */ : TextFile -> Integer; GetBoolean /*#NAME 'GetB' */ : TextFile -> Boolean; GetCharstring /*#NAME 'GetCS' */ : TextFile -> Charstring; GetCharacter /*#NAME 'GetC' */ : TextFile -> Character; GetString /*#NAME 'GetStr' */ : TextFile -> Charstring; GetLine /*#NAME 'GetLn' */ : TextFile -> Charstring; GetSeed /*#NAME 'GetS' */ : TextFile -> Integer; /*#ADT (T A(S) E(S) R(H) W(H) D(H) HP) #TYPE #define MAXFILENAME 256 #ifndef XMONITOR #include #endif #if defined(SUN4_1_1CC) || defined(SUN4_1_1GCC) #include #endif typedef FILE * TextFile; #ifdef XREADANDWRITEF static char yCTemp_TextFile[MAXFILENAME]; #endif #HEADING #define TextFileNull() (TextFile)0 #ifndef XUSE_GENERIC_FUNC #define yDef_TextFile(F) *F = (TextFile)0 #endif #define stdin1() stdin #define stdout1() stdout #define stderr1() stderr #ifdef LOUIS #define stdin2() "Lstdin" #define stdout2() "Lstdout" #define stderr2() "Lstderr" #endif #ifdef XREADANDWRITEF extern int yRead_TextFile (void *Result); extern char *yWri_TextFile (void *C); #endif extern TextFile Flush (TextFile F); extern TextFile GetAndOpenR (SDL_Charstring Prompt); extern TextFile GetAndOpenW (SDL_Charstring Prompt); extern TextFile OpenR (SDL_Charstring FName); extern TextFile OpenW (SDL_Charstring FName); extern TextFile OpenA (SDL_Charstring FName); #define Close(P) CloseF(P); P=TextFileNull() extern TextFile CloseF (TextFile F); extern SDL_Boolean IsOpened (TextFile F); extern SDL_Boolean AtEOF (TextFile F); extern SDL_Boolean AtLastChar (TextFile F); extern void xPutValue (TextFile F, xSortIdNode SortId, void * Value, char * FunctionName); extern TextFile PutReal (TextFile F, SDL_Real V); extern TextFile PutTime (TextFile F, SDL_Time V); extern TextFile PutDuration (TextFile F, SDL_Duration V); extern TextFile PutPid (TextFile F, SDL_PId V); extern TextFile PutInteger (TextFile F, SDL_Integer V); extern TextFile PutBoolean (TextFile F, SDL_Boolean V); extern TextFile PutCharacter (TextFile F, SDL_Character V); extern TextFile PutCharstring (TextFile F, SDL_Charstring V); extern TextFile PutString (TextFile F, SDL_Charstring V); extern TextFile PutLine (TextFile F, SDL_Charstring V); extern TextFile PutNewLine (TextFile F); extern void xGetValue (TextFile F, SDL_Charstring Prompt, xSortIdNode SortId, void * Result, char * FunctionName); extern SDL_Real GetReal (TextFile F, SDL_Charstring Prompt); extern SDL_Time GetTime (TextFile F, SDL_Charstring Prompt); extern SDL_Duration GetDuration (TextFile F, SDL_Charstring Prompt); extern SDL_PId GetPid (TextFile F, SDL_Charstring Prompt); extern SDL_Integer GetInteger (TextFile F, SDL_Charstring Prompt); extern SDL_Boolean GetBoolean (TextFile F, SDL_Charstring Prompt); extern SDL_Character GetCharacter (TextFile F, SDL_Charstring Prompt); extern SDL_Charstring GetCharstring (TextFile F, SDL_Charstring Prompt); extern SDL_Charstring GetString (TextFile F, SDL_Charstring Prompt); extern SDL_Charstring GetLine (TextFile F, SDL_Charstring Prompt); extern SDL_Integer GetSeed (TextFile F, SDL_Charstring Prompt); #define GetR(F) (GetReal(F, \ SDL_CHARSTRING_LIT("LReal: ", "Real: "))) #define GetT(F) (GetTime(F, \ SDL_CHARSTRING_LIT("LTime: ", "Time: "))) #define GetD(F) (GetDuration(F, \ SDL_CHARSTRING_LIT("LDuration: ", "Duration: "))) #define GetP(F) (GetPid(F, \ SDL_CHARSTRING_LIT("LPId: ", "PId: "))) #define GetI(F) (GetInteger(F, \ SDL_CHARSTRING_LIT("LInteger: ", "Integer: "))) #define GetB(F) (GetBoolean(F, \ SDL_CHARSTRING_LIT("LBoolean: ", "Boolean: "))) #define GetC(F) (GetCharacter(F, \ SDL_CHARSTRING_LIT("LCharacter: ", "Character: "))) #define GetCS(F) (GetCharstring(F, \ SDL_CHARSTRING_LIT("LCharstring: ", "Charstring: "))) #define GetStr(F) (GetString(F, \ SDL_CHARSTRING_LIT("LCharstring: ", "Charstring: "))) #define GetLn(F) (GetLine(F, \ SDL_CHARSTRING_LIT("LCharstring: ", "Charstring: "))) #define GetS(F) (GetSeed(F, \ SDL_CHARSTRING_LIT("LSeed: ", "Seed: "))) extern int pfread (FILE *file, char *buf, int buflen, long position); extern char *pfgets (char *buf, int buflen, FILE *file); #BODY #ifdef XREADANDWRITEF static int NFiles = 0; static char *NameOfFile[FOPEN_MAX]; static FILE *FilePtr[FOPEN_MAX]; int isAssign = 0; int yRead_TextFile(void *Result) { #ifdef XMONITOR xPrintString("\n+=====================================================+\n"); xPrintString("You can not change a File Descriptor value in run-time!\n"); #else printf("\n+=====================================================+\n"); printf("You can not change a File Descriptor value in run-time!\n"); #endif Result = Result; return 0; } char *yWri_TextFile(void * C) { int i=0; FILE *temp = *(FILE **)C; if(!isAssign)xPrintString("I/O on "); isAssign = 0; if (temp == stdin) strcpy(yCTemp_TextFile,"stdin"); else if (temp == stdout)strcpy(yCTemp_TextFile,"stdout"); else if (temp == stderr)strcpy(yCTemp_TextFile,"stderr"); else if (temp == NULL) strcpy(yCTemp_TextFile,"NULL"); else { while (iName); } else { Prompt++; strcpy(strVar1, Prompt); COMMENT( Prompt should end with ": " for SimUI ) if (Prompt[strlen(Prompt)-2] != ':' || Prompt[strlen(Prompt)-1] != ' ') { strcat(strVar1, ": "); } } xPrintString(strVar1); while (! xReadSort(Result, SortId)) { xPrintString("Error in value\n"); *xInputPos = '\0'; xPrintString(strVar1); } *xInputPos = '\0'; return; } else { Index = 0; while ((intVar = fgetc(F)) != EOF && intVar != '\n') strVar[Index++] = (char)intVar; strVar[Index] = '\0'; xChangeInputLine(strVar); if (! xReadSort(Result, SortId)) { sprintf(strVar1, "Illegal value found by %s. Line:\n", FunctionName); xPrintString(strVar1); xPrintString(strVar); xPrintString("\n\nSimulation terminated\n"); SDL_Halt(); } xRestoreInputLine(); return; } #else fprintf (stderr, "\nxGetValue does not work with Application library\n"); #endif } SDL_Real GetReal(TextFile F, SDL_Charstring Prompt) { SDL_Real Result = 0.0; #ifdef XMONITOR if (F == stdin) { xGetValue(F, Prompt, xSrtN_SDL_Real, (void *)&Result, "GetReal"); return Result; } #endif fscanf (F, "%lf", &Result); return Result; } SDL_Time GetTime(TextFile F, SDL_Charstring Prompt) { SDL_Time Result; double t; #if !defined(XTIMEASINT_TICKS) && !defined(XTIMEASINT_SECS) Result.s = 0; Result.ns = 0; #else Result = 0; #endif #ifdef XMONITOR if (F == stdin) { xGetValue(F, Prompt, xSrtN_SDL_Time, (void *)&Result, "GetTime"); return Result; } #endif fscanf (F, "%lf", &t); Result.s = (int) t; Result.ns = (int) ((t - (double) (Result.s)) * 1000000000.0); return Result; } SDL_Duration GetDuration(TextFile F, SDL_Charstring Prompt) { SDL_Duration Result; double t; #if !defined(XTIMEASINT_TICKS) && !defined(XTIMEASINT_SECS) Result.s = 0; Result.ns = 0; #else Result = 0; #endif #ifdef XMONITOR if (F == stdin) { xGetValue(F, Prompt, xSrtN_SDL_Duration, (void *)&Result, "GetDuration"); return Result; } #endif fscanf (F, "%lf", &t); Result.s = (int) t; Result.ns = (int) ((t - (double) (Result.s)) * 1000000000.0); return Result; } SDL_PId GetPid(TextFile F, SDL_Charstring Prompt) { SDL_PId Result; Result = SDL_NULL; #ifdef XMONITOR if (F == stdin) { xGetValue(F, Prompt, xSrtN_SDL_PId, (void *)&Result, "GetPid"); } #else fprintf (stderr, "GetPid does not work with Application library"); #endif return Result; } SDL_Integer GetInteger(TextFile F, SDL_Charstring Prompt) { SDL_Integer Result = 0; #ifdef XMONITOR if (F == stdin) { xGetValue(F, Prompt, xSrtN_SDL_Integer, (void *)&Result, "GetInteger"); return Result; } #endif fscanf (F, "%d", &Result); return Result; } SDL_Boolean GetBoolean(TextFile F, SDL_Charstring Prompt) { #ifdef XMONITOR SDL_Boolean Result = 0; #endif char buf[256]; #ifdef XMONITOR if (F == stdin) { xGetValue(F, Prompt, xSrtN_SDL_Boolean, (void *)&Result, "GetBoolean"); return Result; } #endif fscanf (F, "%s", buf); if (strcmp (buf, "true") == 0) return SDL_True; else if (strcmp (buf, "false") == 0) return SDL_False; else { fprintf (stderr, "Illegal value in input (GetBoolean): %s", buf); return SDL_False; } } SDL_Character GetCharacter( TextFile F, SDL_Charstring Prompt) { #ifdef XMONITOR SDL_Character Result = '\0'; if (F == stdin) { xGetValue(F, Prompt, xSrtN_SDL_Character, (void *)&Result, "GetCharacter"); return Result; } #endif return getc (F); } SDL_Charstring GetCharstring( TextFile F, SDL_Charstring Prompt) { SDL_Charstring Result = (SDL_Charstring)0; #ifdef XMONITOR xGetValue(F, Prompt, xSrtN_SDL_Charstring, (void *)&Result, "GetCharstring"); #else char buf[500], *first, *last; int ok; pfgets (buf, 499, F); for (first = buf; *first != '\0' && *first != '\''; ++first) ; ok = *first == '\''; if (ok) { for (last = first+1; *last != '\0' && *last != '\''; ++last) ; ok = *last == '\''; } if (ok) { *first = 'L'; *last = '\0'; xAss_SDL_Charstring (&Result, first, XASS_MR_TMP_NF); } else { fprintf (stderr, "\nIllegal value in GetCharstring: %s\n", buf); xAss_SDL_Charstring (&Result, "Lerror!", XASS_MR_TMP_NF); } #endif return Result; } SDL_Charstring GetString( TextFile F, SDL_Charstring Prompt) { SDL_Charstring Result = (SDL_Charstring)0; char buf[500]; #ifdef XMONITOR if (F == stdin) { xGetValue(F, Prompt, xSrtN_SDL_Charstring, (void *)&Result, "GetString"); return Result; } #endif buf[0] = 'L'; fscanf (F, " %s", &buf[1]); xAss_SDL_Charstring (&Result, buf, XASS_MR_TMP_NF); return Result; } SDL_Charstring GetLine( TextFile F, SDL_Charstring Prompt) { SDL_Charstring Result = (SDL_Charstring)0; char buf[500]; int len; #ifdef XMONITOR if (F == stdin) { xGetValue(F, Prompt, xSrtN_SDL_Charstring, (void *)&Result, "GetString"); return Result; } #endif buf[0] = 'L'; pfgets (&buf[1], 499, F); len = strlen (buf); if (len > 0 && buf[len-1] == '\n') buf[len-1] = '\0'; xAss_SDL_Charstring (&Result, buf, XASS_MR_TMP_NF); return Result; } SDL_Integer GetSeed(TextFile F, SDL_Charstring Prompt) { SDL_Integer Result; while (1) { Result = GetInteger(F, Prompt); if ((Result<=32767) && (Result>=1) && ((Result)%2==1)) return Result; #ifdef XMONITOR xPrintString("Seed should be odd integer in range 1 to 32767\n"); *xInputPos = '\0'; #else printf ("Seed should be odd integer in range 1 to 32767\n"); #endif } } int pfread(FILE *file, char *buf, int buflen, long position) { #ifndef __cplusplus #if defined (SUN5_ANSICC) || defined (SUN5_CC) return pread(fileno(file),buf,buflen,position); #else int result; fseek(file, position, SEEK_SET); result = fread(buf, buflen,1,file); fseek(file, position, SEEK_SET); return result * buflen; #endif #else int result; fseek(file, position, SEEK_SET); result = fread(buf, buflen,1,file); fseek(file, position, SEEK_SET); return result * buflen; #endif } #if defined (__BORLANDC__) #ifdef __cplusplus #include #endif #endif char *pfgets(char *buf, int buflen, FILE *file) { #if !defined (__BORLANDC__) return fgets(buf,buflen,file); #else int jb=0; #ifdef __cplusplus while(jb