void AsmPass1(Assembler *a, char *text) { // 第一階段的組譯 int i, address = 0, number; Array* lines = split(text, "\r\n", REMOVE_SPLITER); // 將組合語言分割成一行一行 ArrayEach(lines, strPrintln); // 印出以便觀察 printf("=================PASS1================\n"); for (i=0; i<lines->count; i++) { // 對於每一行 strReplace(lines->item[i], ";", '\0'); strReplace(lines->item[i], "\t", ' '); AsmCode *code = AsmCodeNew(lines->item[i]); // 建立指令物件 if (code == NULL) continue; code->address = address; // 設定該行的位址 Op *op = NULL; if (code->op != NULL) { op = HashTableGet(opTable, code->op); // 查詢運算碼 if (op != NULL) { // 如果查到 code->opCode = op->code; // 設定運算碼 code->type = op->type; // 設定型態 } } if (code->label != NULL) // 如果有標記符號 HashTablePut(a->symTable, code->label, code); // 加入符號表中 ArrayAdd(a->codes, code); // 建構指令物件陣列 AsmCodePrintln(code); // 印出觀察 code->size = AsmCodeSize(code); // 計算指令大小 address += code->size; // 計算下一個指令位址 } ArrayFree(lines, strFree); // 釋放記憶體 }
int Cache_AddDependency (/*in*/ req * r, /*in*/ tCacheItem * pItem, /*in*/ tCacheItem * pDependsOn) { int n ; if (!pItem -> pDependsOn) ArrayNew (r -> pApp, &pItem -> pDependsOn, 2, sizeof (tCacheItem *)) ; n = ArrayAdd (r -> pApp, &pItem -> pDependsOn, 1) ; pItem -> pDependsOn[n] = pDependsOn ; if (!pDependsOn -> pNeededFor) ArrayNew (r -> pApp, &pDependsOn -> pNeededFor, 2, sizeof (tCacheItem *)) ; n = ArrayAdd (r -> pApp, &pDependsOn -> pNeededFor, 1) ; pDependsOn -> pNeededFor[n] = pItem ; return ok ; }
int Cache_SetNotExpired (/*in*/ req * r, /*in*/ tCacheItem * pItem) { pItem -> nLastChecked = r -> nRequestCount ; pItem -> nLastUpdated = r -> nRequestCount ; pItem -> nLastModified = r -> nRequestTime ; pItem -> bExpired = FALSE ; if (!pItem -> bCache) { int n = ArrayAdd(r -> pApp, &pCachesToRelease, 1) ; pCachesToRelease[n] = pItem ; } return ok ; }
int main() { //~ Function 1 int a = 1; int b = 2; printf("int a equals %d\n", a); printf("int b equals %d\n", b); SwapValues(&a, &b); printf("Values swapped\n"); printf("int a now equals %d\n", a); printf("int b now equals %d\n", b); int arr[5] = {1, 2, 3, 4, 5}; int len = 5; //~ Function 2 printf("New temp variable the sum is: %d\n", GetSumReturn(arr, len)); //~ Function 3 int sum = 0; printf("The sum value is now: %d\n", sum); GetSumParameter(arr, len, &sum); printf("Sum value changed\n"); printf("The sum value is now: %d\n", sum); //~ Function 4 int arr2[5] = {1, 2, 3, 4, 5}; int result[5]; int i = 0; for(; i != len; i++) { printf("%d\n", result[i]); } ArrayAdd(arr, arr2, len, result); i = 0; for(; i != len; i++) { printf("%d\n", result[i]); } return 0; }
int main(int argc, char **argv) { char *progname; FILE *plist_file; char **ignore, *prefix; int opt, stripcount, i; PListEntry *files, *dirs; progname = strrchr(argv[0], '/'); if (progname == NULL) progname = argv[0]; else progname++; plist_file = NULL; ignore = NULL; prefix = NULL; stripcount = 0; while ((opt = getopt(argc, argv, "d:f:i:p:s:")) != -1) { switch (opt) { case 'd': if (chdir(optarg)) { perror(optarg); return EXIT_FAILURE; } break; case 'f': if (plist_file != NULL) (void)fclose(plist_file); if ((plist_file = fopen(optarg, "a")) == NULL) { perror(optarg); return EXIT_FAILURE; } break; case 'i': ignore = ArrayAdd(ignore, optarg); break; case 'p': if (strlen(optarg) > 0) prefix = optarg; break; case 's': stripcount = atoi(optarg); if (stripcount <= 0) { (void)fprintf(stderr, "%s: -s argument \"%s\" " "must be a positive integer.\n", progname, optarg); return EXIT_FAILURE; } break; default: Usage(progname); } } if (argc == optind) Usage(progname); if (prefix != NULL && prefix[strlen(prefix) - 1] != '/') prefix = StrCat(prefix, "/"); files = NULL; dirs = NULL; for (i = optind; i < argc ; i++) ProcessRPM(argv[i], &files, &dirs, ignore, prefix, stripcount); if (plist_file != NULL) { PListWrite(files, dirs, plist_file); (void)fclose(plist_file); } return EXIT_SUCCESS; }