void GdlPass::DebugFsmTable(GrcManager * pcman, std::ostream & strmOut, bool fWorking) { int cfsmc = m_pfsm->NumberOfColumns(); if (fWorking) strmOut << "\nWorking Table: "; else strmOut << "\nFinal Table: "; int ifsmc; for (ifsmc = 0; ifsmc < cfsmc; ifsmc++) // column headers OutputNumber(strmOut, ifsmc, 6); strmOut << "\n "; for (ifsmc = 0; ifsmc < cfsmc; ifsmc++) strmOut << "- - - "; int ifsLim = (fWorking)? m_pfsm->RawNumberOfStates() : m_vifsFinalToWork.Size(); for (int ifs = 0; ifs < ifsLim; ifs++) { FsmState * pfstate = (fWorking) ? m_pfsm->RawStateAt(ifs) : m_pfsm->StateAt(m_vifsFinalToWork[ifs]); strmOut << "\n" << ifs << ": " << pfstate->SlotsMatched() << "\n"; if (pfstate->HasBeenMerged()) { Assert(fWorking); strmOut << " => state #" << pfstate->MergedState()->WorkIndex(); } else { strmOut << " "; for (int ifsmc = 0; ifsmc < cfsmc; ifsmc++) { strmOut << " "; int ifsmcValue = pfstate->CellValue(ifsmc); if (!fWorking) { if (m_pfsm->RawStateAt(ifsmcValue)->HasBeenMerged()) ifsmcValue = m_pfsm->RawStateAt(ifsmcValue)->MergedState()->WorkIndex(); ifsmcValue = m_vifsWorkToFinal[ifsmcValue]; } OutputNumber(strmOut, ifsmcValue, 5); } } pfstate->DebugFsmState(strmOut, ifs); } strmOut << "\n "; for (ifsmc = 0; ifsmc < cfsmc; ifsmc++) strmOut << "- - - "; strmOut << "\n\n"; }
int main() { int *pArray; pArray=(int *)malloc(sizeof(int ) * NUMBER); InputNumber(pArray,NUMBER); Exchange(pArray,NUMBER); OutputNumber(pArray,NUMBER); return 0; }
void InputNumber(int *pArray,int number) { /*for(int i=0;i<10;i++) { *(pArray +i)=100-i+i*10+13; } *(pArray +2)=25; *(pArray + 4)=222; *(pArray + 6)=33; *(pArray+ 8)=322;*/ printf("please input %d numbers\n",NUMBER); for(int i=0;i<NUMBER;i++) { printf("input number:"); scanf("%d",pArray + i); } printf("origin:"); OutputNumber(pArray,NUMBER); }
static int PerformLine(int ct) { int continuation=0; int param[5],pptr=0; int act[4]; int cc=0; while(cc<5) { int cv,dv; cv=Actions[ct].Condition[cc]; dv=cv/20; cv%=20; switch(cv) { case 0: param[pptr++]=dv; break; case 1: if(Items[dv].Location!=CARRIED) return(0); break; case 2: if(Items[dv].Location!=MyLoc) return(0); break; case 3: if(Items[dv].Location!=CARRIED&& Items[dv].Location!=MyLoc) return(0); break; case 4: if(MyLoc!=dv) return(0); break; case 5: if(Items[dv].Location==MyLoc) return(0); break; case 6: if(Items[dv].Location==CARRIED) return(0); break; case 7: if(MyLoc==dv) return(0); break; case 8: if((BitFlags&(1<<dv))==0) return(0); break; case 9: if(BitFlags&(1<<dv)) return(0); break; case 10: if(CountCarried()==0) return(0); break; case 11: if(CountCarried()) return(0); break; case 12: if(Items[dv].Location==CARRIED||Items[dv].Location==MyLoc) return(0); break; case 13: if(Items[dv].Location==0) return(0); break; case 14: if(Items[dv].Location) return(0); break; case 15: if(CurrentCounter>dv) return(0); break; case 16: if(CurrentCounter<=dv) return(0); break; case 17: if(Items[dv].Location!=Items[dv].InitialLoc) return(0); break; case 18: if(Items[dv].Location==Items[dv].InitialLoc) return(0); break; case 19:/* Only seen in Brian Howarth games so far */ if(CurrentCounter!=dv) return(0); break; } cc++; } /* Actions */ act[0]=Actions[ct].Action[0]; act[2]=Actions[ct].Action[1]; act[1]=act[0]%150; act[3]=act[2]%150; act[0]/=150; act[2]/=150; cc=0; pptr=0; while(cc<4) { if(act[cc]>=1 && act[cc]<52) { Output(Messages[act[cc]]); Output("\n"); } else if(act[cc]>101) { Output(Messages[act[cc]-50]); Output("\n"); } else switch(act[cc]) { case 0:/* NOP */ break; case 52: if(CountCarried()==GameHeader.MaxCarry) { if(Options&YOUARE) Output("You are carrying too much. "); else Output("I've too much to carry! "); break; } Items[param[pptr++]].Location= CARRIED; break; case 53: Items[param[pptr++]].Location=MyLoc; break; case 54: MyLoc=param[pptr++]; break; case 55: Items[param[pptr++]].Location=0; break; case 56: BitFlags|=1<<DARKBIT; break; case 57: BitFlags&=~(1<<DARKBIT); break; case 58: BitFlags|=(1<<param[pptr++]); break; case 59: Items[param[pptr++]].Location=0; break; case 60: BitFlags&=~(1<<param[pptr++]); break; case 61: if(Options&YOUARE) Output("You are dead.\n"); else Output("I am dead.\n"); BitFlags&=~(1<<DARKBIT); MyLoc=GameHeader.NumRooms;/* It seems to be what the code says! */ break; case 62: { /* Bug fix for some systems - before it could get parameters wrong */ int i=param[pptr++]; Items[i].Location=param[pptr++]; break; } case 63: doneit: Output("The game is now over.\n"); glk_exit(); case 64: break; case 65: { int i=0; int n=0; while(i<=GameHeader.NumItems) { if(Items[i].Location==GameHeader.TreasureRoom && *Items[i].Text=='*') n++; i++; } if(Options&YOUARE) Output("You have stored "); else Output("I've stored "); OutputNumber(n); Output(" treasures. On a scale of 0 to 100, that rates "); OutputNumber((n*100)/GameHeader.Treasures); Output(".\n"); if(n==GameHeader.Treasures) { Output("Well done.\n"); goto doneit; } break; } case 66: { int i=0; int f=0; if(Options&YOUARE) Output("You are carrying:\n"); else Output("I'm carrying:\n"); while(i<=GameHeader.NumItems) { if(Items[i].Location==CARRIED) { if(f==1) { if (Options & TRS80_STYLE) Output(". "); else Output(" - "); } f=1; Output(Items[i].Text); } i++; } if(f==0) Output("Nothing"); Output(".\n"); break; } case 67: BitFlags|=(1<<0); break; case 68: BitFlags&=~(1<<0); break; case 69: GameHeader.LightTime=LightRefill; Items[LIGHT_SOURCE].Location=CARRIED; BitFlags&=~(1<<LIGHTOUTBIT); break; case 70: ClearScreen(); /* pdd. */ break; case 71: SaveGame(); break; case 72: { int i1=param[pptr++]; int i2=param[pptr++]; int t=Items[i1].Location; Items[i1].Location=Items[i2].Location; Items[i2].Location=t; break; } case 73: continuation=1; break; case 74: Items[param[pptr++]].Location= CARRIED; break; case 75: { int i1,i2; i1=param[pptr++]; i2=param[pptr++]; Items[i1].Location=Items[i2].Location; break; } case 76: /* Looking at adventure .. */ break; case 77: if(CurrentCounter>=0) CurrentCounter--; break; case 78: OutputNumber(CurrentCounter); break; case 79: CurrentCounter=param[pptr++]; break; case 80: { int t=MyLoc; MyLoc=SavedRoom; SavedRoom=t; break; } case 81: { /* This is somewhat guessed. Claymorgue always seems to do select counter n, thing, select counter n, but uses one value that always seems to exist. Trying a few options I found this gave sane results on ageing */ int t=param[pptr++]; int c1=CurrentCounter; CurrentCounter=Counters[t]; Counters[t]=c1; break; } case 82: CurrentCounter+=param[pptr++]; break; case 83: CurrentCounter-=param[pptr++]; if(CurrentCounter< -1) CurrentCounter= -1; /* Note: This seems to be needed. I don't yet know if there is a maximum value to limit too */ break; case 84: Output(NounText); break; case 85: Output(NounText); Output("\n"); break; case 86: Output("\n"); break; case 87: { /* Changed this to swap location<->roomflag[x] not roomflag 0 and x */ int p=param[pptr++]; int sr=MyLoc; MyLoc=RoomSaved[p]; RoomSaved[p]=sr; break; } case 88: delay(2); break; case 89: pptr++; /* SAGA draw picture n */ /* Spectrum Seas of Blood - start combat ? */ /* Poking this into older spectrum games causes a crash */ break; default: fprintf(stderr,"Unknown action %d [Param begins %d %d]\n", act[cc],param[pptr],param[pptr+1]); break; } cc++; } return(1+continuation); }
void glk_main(void) { FILE *f; int vb,no; Bottom = glk_window_open(0, 0, 0, wintype_TextBuffer, 1); if(Bottom == NULL) glk_exit(); glk_set_window(Bottom); if(game_file == NULL) Fatal("No game provided"); f = fopen(game_file, "r"); if(f==NULL) Fatal("Cannot open game"); if (Options & TRS80_STYLE) { Width = 64; TopHeight = 11; } else { Width = 80; TopHeight = 10; } if(split_screen) { Top = glk_window_open(Bottom, winmethod_Above | winmethod_Fixed, TopHeight, wintype_TextGrid, 0); if(Top == NULL) { split_screen = 0; Top = Bottom; } } else { Top = Bottom; } Output("\ Scott Free, A Scott Adams game driver in C.\n\ Release 1.14, (c) 1993,1994,1995 Swansea University Computer Society.\n\ Distributed under the GNU software license\n\n"); LoadDatabase(f,(Options&DEBUGGING)?1:0); fclose(f); srand(time(NULL)); while(1) { glk_tick(); PerformActions(0,0); Look(); if(GetInput(&vb,&no) == -1) continue; switch(PerformActions(vb,no)) { case -1:Output("I don't understand your command. "); break; case -2:Output("I can't do that yet. "); break; } /* Brian Howarth games seem to use -1 for forever */ if(Items[LIGHT_SOURCE].Location/*==-1*/!=DESTROYED && GameHeader.LightTime!= -1) { GameHeader.LightTime--; if(GameHeader.LightTime<1) { BitFlags|=(1<<LIGHTOUTBIT); if(Items[LIGHT_SOURCE].Location==CARRIED || Items[LIGHT_SOURCE].Location==MyLoc) { if(Options&SCOTTLIGHT) Output("Light has run out! "); else Output("Your light has run out. "); } if(Options&PREHISTORIC_LAMP) Items[LIGHT_SOURCE].Location=DESTROYED; } else if(GameHeader.LightTime<25) { if(Items[LIGHT_SOURCE].Location==CARRIED || Items[LIGHT_SOURCE].Location==MyLoc) { if(Options&SCOTTLIGHT) { Output("Light runs out in "); OutputNumber(GameHeader.LightTime); Output(" turns. "); } else { if(GameHeader.LightTime%5==0) Output("Your light is growing dim. "); } } } } } }
char* ClassLong::Print() { return OutputNumber(this->number); }
int main(int argc, char *argv[]) { xlsWorkBook* pWB; xlsWorkSheet* pWS; unsigned int i; int justList = 0; char *sheetName = ""; if(argc < 2) { Usage(argv[0]); } optind = 2; // skip file arg int ch; while ((ch = getopt(argc, argv, "lt:e:q:f:")) != -1) { switch (ch) { case 'l': justList = 1; break; case 'e': encoding = strdup(optarg); break; case 't': sheetName = strdup(optarg); break; case 'q': stringSeparator = optarg[0]; break; case 'f': fieldSeparator = strdup(optarg); break; default: Usage(argv[0]); break; } } struct st_row_data* row; WORD cellRow, cellCol; // open workbook, choose standard conversion pWB = xls_open(argv[1], encoding); if (!pWB) { fprintf(stderr, "File not found"); fprintf(stderr, "\n"); return EXIT_FAILURE; } // check if the requested sheet (if any) exists if (sheetName[0]) { for (i = 0; i < pWB->sheets.count; i++) { if (strcmp(sheetName, pWB->sheets.sheet[i].name) == 0) { break; } } if (i == pWB->sheets.count) { fprintf(stderr, "Sheet \"%s\" not found", sheetName); fprintf(stderr, "\n"); return EXIT_FAILURE; } } // process all sheets for (i = 0; i < pWB->sheets.count; i++) { int isFirstLine = 1; // just looking for sheet names if (justList) { printf("%s\n", pWB->sheets.sheet[i].name); continue; } // check if this the sheet we want if (sheetName[0]) { if (strcmp(sheetName, pWB->sheets.sheet[i].name) != 0) { continue; } } // open and parse the sheet pWS = xls_getWorkSheet(pWB, i); xls_parseWorkSheet(pWS); // process all rows of the sheet for (cellRow = 0; cellRow <= pWS->rows.lastrow; cellRow++) { int isFirstCol = 1; row = xls_row(pWS, cellRow); // process cells if (!isFirstLine) { printf("%s", lineSeparator); } else { isFirstLine = 0; } for (cellCol = 0; cellCol <= pWS->rows.lastcol; cellCol++) { //printf("Processing row=%d col=%d\n", cellRow+1, cellCol+1); xlsCell *cell = xls_cell(pWS, cellRow, cellCol); if ((!cell) || (cell->isHidden)) { continue; } if (!isFirstCol) { printf("%s", fieldSeparator); } else { isFirstCol = 0; } // display the colspan as only one cell, but reject rowspans (they can't be converted to CSV) if (cell->rowspan > 1) { fprintf(stderr, "Warning: %d rows spanned at col=%d row=%d: output will not match the Excel file.\n", cell->rowspan, cellCol+1, cellRow+1); } // display the value of the cell (either numeric or string) if (cell->id == 0x27e || cell->id == 0x0BD || cell->id == 0x203) { OutputNumber(cell->d); } else if (cell->id == 0x06) { // formula if (cell->l == 0) // its a number { OutputNumber(cell->d); } else { if (!strcmp(cell->str, "bool")) // its boolean, and test cell->d { OutputString((int) cell->d ? "true" : "false"); } else if (!strcmp(cell->str, "error")) // formula is in error { OutputString("*error*"); } else // ... cell->str is valid as the result of a string formula. { OutputString(cell->str); } } } else if (cell->str != NULL) { OutputString(cell->str); } else { OutputString(""); } } } xls_close_WS(pWS); } xls_close(pWB); return EXIT_SUCCESS; }
T_void CompileArgs(T_byte8 *p_args, T_word16 numArgs) { char args[10][100] ; T_word16 i, j, k ; T_byte8 arg[100] ; T_sword32 value ; T_word16 len ; p_args++ ; if (numArgs == 0) p_args++ ; for (i=0; i<numArgs; i++) { j = 0 ; while ((*p_args != ',') && (*p_args != ')')) { if (j==100) { printf("Argument %d on line %d too long!\n", i+1, G_line) ; G_errors++ ; return ; } args[i][j++] = *(p_args++) ; } if ((p_args[0] == ')') && ((i+1) != numArgs)) { printf("Error! Wrong number of arguments on line %d\n", G_line) ; G_errors++ ; return ; } args[i][j] = '\0' ; p_args++ ; } if (p_args[-1] != ')') { printf("Error! Wrong number of arguments on line %d\n", G_line) ; G_errors ++ ; return ; } for (i=0; i<numArgs; i++) { //printf("arg[%d] = '%s'\n", i, args[i]) ; strcpy(arg, args[i]) ; Strip(arg) ; if ((arg[0] == '-') || (isdigit(arg[0]))) { /* Arg is Number. */ value = atol(arg) ; OutputNumber(value) ; } else if (arg[0] == '&') { /* Event. */ value = atol(arg+1) ; if (!((value >= 1) && (value <= 3))) { printf("Error! Event parameter (%ld) out of range (1-3) on line %d!\n", value, G_line) ; G_errors++ ; return ; } OutputByte(SCRIPT_DATA_TYPE_EVENT_PARAMETER) ; OutputByte((T_byte8)value) ; } else if (arg[0] == QUOTE_START) { len = strlen(arg)-2 ; if (len >= 80) { printf("Error! String too long on line %d!\n", G_line) ; G_errors++ ; return ; } OutputByte(SCRIPT_DATA_TYPE_STRING) ; OutputByte((T_byte8)len) ; for (k=0; k<len; k++) { OutputByte(arg[1+k]) ; } } else { /* Try doing a flag name. */ value = FindFlag(arg) ; if (value != -1) { OutputByte(SCRIPT_DATA_TYPE_FLAG) ; OutputByte((T_byte8)value) ; } else { value = FindVar(arg) ; if (value != -1) { value = G_vars[value].number ; OutputByte(SCRIPT_DATA_TYPE_VARIABLE) ; OutputByte(((T_byte8 *)&value)[0]) ; OutputByte(((T_byte8 *)&value)[1]) ; } else { //printf("Searching for defnum: %s\n", arg) ; value = FindDefnum(arg) ; if (value != -1) { value = G_defnums[value].number ; //printf("Output defnum: %s %ld\n", arg, value) ; OutputNumber(value) ; } else { printf("Error! Unknown argument '%s' on line %d\n", arg, G_line) ; G_errors++ ; return ; } } } } } }