/** * tests helper functions is_var() and is_op() */ static char * test_helpers() { char tmp[VAR_LENGTH+1], str[LINE_LENGTH]; char * trimmed; int ret, i; printf("Testing %s\n", __FUNCTION__); /* test is_var() from A-Z */ for (i='A'; i<='Z'; i++) { tmp[0] = i; tmp[1] = '\0'; ret = is_var(tmp); mu_assert("error, ret != 1", ret == 1); } /* test bogus inputs */ /* small letter */ tmp[0] = 'a'; ret = is_var(tmp); mu_assert("error, ret != 0", ret == 0); /* number */ tmp[0] = '1'; ret = is_var(tmp); mu_assert("error, ret != 0", ret == 0); /* test is_op */ tmp[0] = '+'; ret = is_op(tmp); mu_assert("error, ret != 1", ret == 1); tmp[0] = '-'; ret = is_op(tmp); mu_assert("error, ret != 1", ret == 1); tmp[0] = '*'; ret = is_op(tmp); mu_assert("error, ret != 1", ret == 1); tmp[0] = '/'; ret = is_op(tmp); mu_assert("error, ret != 1", ret == 1); /* test bogus inputs */ tmp[0] = '='; ret = is_op(tmp); mu_assert("error, ret != 0", ret == 0); tmp[0] = '^'; ret = is_op(tmp); mu_assert("error, ret != 0", ret == 0); tmp[0] = '$'; ret = is_op(tmp); mu_assert("error, ret != 0", ret == 0); /* test trim_space() */ strcpy(str, "\t\tFD 30 \t\t "); trimmed = trim_space(str); mu_assert("error, trimmed != \"FD 30\"", strsame(trimmed, "FD 30")); strcpy(str, " \t \tDO A FROM 1 TO 8 { \t\t "); trimmed = trim_space(str); mu_assert("error, trimmed != \"DO A FROM 1 TO 8 {\"", strsame(trimmed, "DO A FROM 1 TO 8 {")); return 0; }
void parse_input (Tree *T, char *token) { void *check = NULL; int parameter = atoi(token + 1); char instruction[INSTRUCTION]; instruction[1] = '\0'; instruction[0] = toupper((int)token[0]); if (parameter == 0) { ERROR ("A key of integer value zero is not allowed."); } printf("\nReceived: instruction=%s, parameter=%d.\n", instruction,parameter); int *vptr = ¶meter; if (strsame(instruction, "S")) { check = find (T, vptr); if (check) { fprintf (stderr, "Node with key %d was found in the tree.\n", *((int*)check)); } else { fprintf (stderr, "Node with key %d was NOT found in the tree.\n", parameter); check = vptr; } } else if (strsame(instruction, "I")) { check = insert_control (T, vptr); if (check) { fprintf (stderr, "Node with key %d successfully inserted in the tree.\n", *((int*)check)); } } else if (strsame(instruction, "D")) { check = delete_control (T, vptr); if (check) { fprintf (stderr, "Node with key %d successfully deleted from the tree.\n", *((int*)check)); } } if (check == NULL) { fprintf (stderr, "Node with key %d is already in the tree.\n", parameter); } }
int parse_sample_byte_format(char *str, enum SP_sample_byte_fmt *sbf) { char *proc="parse_sample_byte_format " SPHERE_VERSION_STR; if (sp_verbose > 10) fprintf(spfp,"Proc %s:\n",proc); if (str == CNULL) return_err(proc,100,100,"Null sample_byte_format_string"); if (sbf == (enum SP_sample_byte_fmt *)0) return_err(proc,101,101,"Null sbf pointer"); if (strsame(str,"01")) *sbf = SP_sbf_01; else if (strsame(str,"10")) *sbf = SP_sbf_10; else if (strsame(str,"1")) *sbf = SP_sbf_1; else if (strsame(str,"0123")) *sbf = SP_sbf_0123; else if (strsame(str,"1032")) *sbf = SP_sbf_1032; else if (strsame(str,"2301")) *sbf = SP_sbf_2301; else if (strsame(str,"3210")) *sbf = SP_sbf_3210; else if (strsame(str,"N")) *sbf = SP_sbf_N; if (strstr(str,"shortpack") != CNULL) { /* this return value must remain 1000, other functions depend on it*/ return_err(proc,1000,1000, rsprintf("Unknown sample_byte_format value '%s' in header",str)); } if (sp_verbose > 11) fprintf(spfp,"Proc %s: Returning 0\n",proc); return_success(proc,0,0,"ok"); }
void unit_test(void) { CFStringRef good_id = CFSTR("*****@*****.**"); CFStringRef bogus_id = CFSTR("*****@*****.**"); ODRecordRef record = NULL; ODNodeRef node = NULL; char jid[1024]; CFStringRef short_name = CFSTR("korver"); test_assert(! odkerb_has_foreign_realm("foo@bar")); test_assert(odkerb_has_foreign_realm("foo@bar@baz")); test_assert(odkerb_copy_user_record_with_alt_security_identity(bogus_id, &record) != 0); test_assert(odkerb_copy_user_record_with_alt_security_identity(good_id, &record) == 0); test_assert(record != 0); test_assert(odkerb_get_im_handle_with_user_record(record, CFSTR(kIMTypeJABBER), CFSTR("ichatserver.apple.com"), short_name, jid, sizeof(jid)) == 0); test_assert(strsame(jid, "*****@*****.**")); record = 0; CFStringRef config_record_name = odkerb_create_config_record_name(good_id); test_assert(odkerb_copy_search_node_with_config_record_name(config_record_name, &node) == 0); test_assert(node != 0); test_assert(odkerb_copy_user_record_with_short_name(short_name, node, &record) == 0); test_assert(record != 0); test_assert(odkerb_get_im_handle_with_user_record(record, CFSTR(kIMTypeJABBER), CFSTR("ichatserver.apple.com"), short_name, jid, sizeof(jid)) == 0); test_assert(strsame(jid, "*****@*****.**")); record = 0; node = 0; test_assert(odkerb_get_im_handle("[email protected]@SOMEWHERE.ORG", "ichatserver.apple.com", kIMTypeJABBER, jid, sizeof(jid)) == 0); test_assert(strsame(jid, "*****@*****.**")); test_assert(odkerb_get_im_handle("*****@*****.**", "ichatserver.apple.com", kIMTypeJABBER, jid, sizeof(jid)) == 0); test_assert(strsame(jid, "*****@*****.**")); test_assert(odkerb_get_im_handle("[email protected]@SOMEWHERE.ORG", "ichatserver.apple.com", kIMTypeJABBER, jid, sizeof(jid)) != 0); }
Tree *set_tree (char *argv[]) { Tree *tptr; int type_length = strlen (argv[1]); char *tree_type = (char *) malloc ((type_length + 1) * (sizeof(char))); tree_type [type_length - 1] = '\0'; for (int i = 0; i < type_length; i++) { tree_type[i] = toupper ((int)argv[1][i]); } if (strsame (tree_type, "AVL")) { tptr = tree_init(compare_ints, copy_ints, avl_insert_balance, avl_delete_balance); printf("\nAVL tree selected.\n"); } else if (strsame (tree_type, "WAVL")) { tptr = tree_init(compare_ints, copy_ints, wavl_insert_balance, wavl_delete_balance); printf("\nWAVL tree selected.\n"); } else if (strsame (tree_type, "2-3")) { tptr = tree_init(compare_ints, copy_ints, two_three_insert_balance, two_three_delete_balance); printf("\n2-3 tree selected.\n"); } else if (strsame (tree_type, "2-3-4")) { tptr = tree_init(compare_ints, copy_ints, two_four_insert_balance, two_four_delete_balance); printf("\n2-3-4 tree selected.\n"); } else { fprintf (stderr, "Expecting a tree type as the second argument.\n" "The options are 'avl', 'wavl', '2-3' and '2-3-4',\n"); tptr = NULL; } free (tree_type); return tptr; }
bool matches(const char * _name) const { return strsame(name, _name); }
int parse_sample_coding(char *str, int sample_n_bytes, enum SP_sample_encoding *sample_encoding, enum SP_waveform_comp *wav_compress) { int enc_set=FALSE, comp_set=FALSE; char *pstr, *str_mem; char *proc="parse_sample_coding " SPHERE_VERSION_STR; if (sp_verbose > 10) fprintf(spfp,"Proc %s:\n",proc); if (str == CNULL) return_err(proc,101,101,"Null coding string"); if (sample_n_bytes < 1 || sample_n_bytes > 2) { /*then we are assuming the field wasn't set yet, so use the default*/ sample_n_bytes = 0; } if (sample_encoding == (enum SP_sample_encoding *)0) return_err(proc,103,103,"Null sample encoding pointer"); if (wav_compress == (enum SP_waveform_comp *)0) return_err(proc,104,104,"Null waveform compress pointer"); *wav_compress = SP_wc_null; *sample_encoding = SP_se_null; if (sp_verbose > 16) fprintf(spfp,"%s: string IS %s\n",proc,str); /* the algorithm to parse the sample encoding field is : */ /* 1: get a token before a ',' or NULL */ /* 2: set a flag to what it matches */ /* 3: move past the token */ /* 4: loop to (1) */ /* make a duplicate copy because strtok is destructive */ str_mem = mtrf_strdup(str); pstr = strtok(str_mem,","); while (pstr != CNULL){ if (sp_verbose > 16) fprintf(spfp,"%s: token found = %s\n",proc,pstr); if (strsame(pstr,"pcm")){ if (enc_set){ mtrf_free(str_mem); return_err(proc,105,105, "Multiple sample encodings in header field"); } if (sample_n_bytes == 1) *sample_encoding = SP_se_pcm1; else *sample_encoding = SP_se_pcm2; enc_set = TRUE; } else if (strsame(pstr,"ulaw") || strsame(pstr,"mu-law")) { if (enc_set){ mtrf_free(str_mem); return_err(proc,105,105, "Multiple sample encodings in header field"); } *sample_encoding = SP_se_ulaw; enc_set = TRUE; } else if (strsame(pstr,"raw")){ if (enc_set){ mtrf_free(str_mem); return_err(proc,105,105, "Multiple sample encodings in header field"); } *sample_encoding = SP_se_raw; enc_set = TRUE; } else if (strstr(pstr,"embedded-shorten-v") != CNULL) { if (comp_set) { mtrf_free(str_mem); return_err(proc,106,106, "Multiple waveform compressions in header field"); } *wav_compress = SP_wc_shorten; comp_set = TRUE; } else if (strstr(pstr,"embedded-wavpack") != CNULL) { if (comp_set){ mtrf_free(str_mem); return_err(proc,106,106, "Multiple waveform compressions in header field"); } *wav_compress = SP_wc_wavpack; comp_set = TRUE; } else if (strstr(pstr,"embedded-shortpack-v") != CNULL) { if (comp_set){ mtrf_free(str_mem); return_err(proc,106,106, "Multiple waveform compressions in header field"); } *wav_compress = SP_wc_shortpack; comp_set = TRUE; } else { mtrf_free(str_mem); return_err(proc,107,107,"Unknown token in sample coding field"); } pstr = strtok(CNULL,","); } if (*wav_compress == SP_wc_null) *wav_compress = SP_wc_none; if (*sample_encoding == SP_se_null) *sample_encoding = SP_se_pcm2; mtrf_free(str_mem); if (sp_verbose > 11) fprintf(spfp,"Proc %s: Returning 0\n",proc); return_success(proc,0,0,"ok"); }
/* * sp_open * */ SP_FILE *sp_open(char *filename, char *mode) { SP_FILE *tsp; char *errmsg, *proc="sp_open " SPHERE_VERSION_STR, *fopen_mode; enum SP_file_open_mode current_mode; if (sp_verbose > 10) fprintf(spfp,"Proc %s:\n",proc); if (filename == CNULL) return_err(proc,101,SPNULL,"Null filename string"); if (mode == CNULL) return_err(proc,101,SPNULL,"Null file mode string"); if (sp_verbose > 10) fprintf(spfp,"Proc %s: file '%s' mode '%s'\n", proc,filename,mode); if ((tsp=sp_alloc_and_init_sphere_t()) == SPNULL) return_err(proc,102,SPNULL,"Unable to malloc SPFILE memory"); /* set the file open mode in the status structure */ if (strsame(mode,"r")) current_mode = tsp->open_mode = SP_mode_read; else if (strsame(mode,"w")) current_mode = tsp->open_mode = SP_mode_write; else if (strsame(mode,"rv")){ current_mode = tsp->open_mode = SP_mode_read; tsp->read_spifr->status->extra_checksum_verify = TRUE; } else if (strsame(mode,"wv")) { current_mode = tsp->open_mode = SP_mode_write; tsp->write_spifr->status->extra_checksum_verify = TRUE; } else if (strsame(mode,"u")) { tsp->open_mode = SP_mode_read; current_mode = SP_mode_update; } else { free_sphere_t(tsp); return_err(proc,103,SPNULL, rsprintf("Illegal SPFILE open mode '%s'",mode)); } /* just open the file, either for reading or writing. If the */ /* mode was SP_mode_writing, and the file exists, change the mode */ /* to SP_mode_update. */ switch (tsp->open_mode) { case (SP_mode_read): { if (! strsame(filename,"-")) { fopen_mode = (current_mode == SP_mode_read) ? READMODE : UPDATEMODE; if ((tsp->read_spifr->waveform->sp_fp = fopen(filename,fopen_mode)) == (FILE *)0){ free_sphere_t(tsp); return_err(proc,111,SPNULL, rsprintf("%s'%s' for reading fopen mode %s", "Unable to open SPHERE file ", filename,fopen_mode)); } tsp->read_spifr->status->is_disk_file = TRUE; } else { tsp->read_spifr->waveform->sp_fp = stdin; tsp->read_spifr->status->is_disk_file = FALSE; } tsp->read_spifr->status->external_filename = mtrf_strdup(filename); break; } case (SP_mode_write):{ if (! strsame(filename,"-")) { /* open the file, truncating if the file exists */ fopen_mode = (current_mode == SP_mode_write) ? WRITEMODE : UPDATEMODE; if ((tsp->write_spifr->waveform->sp_fp = fopen(filename,fopen_mode)) == (FILE *)0){ free_sphere_t(tsp); return_err(proc,105,SPNULL, rsprintf("Unable to open SPHERE file '%s' for %s %s", filename,"writing, fopen mode",fopen_mode)); } tsp->write_spifr->status->is_disk_file = TRUE; } else { tsp->write_spifr->waveform->sp_fp = stdout; tsp->write_spifr->status->is_disk_file = FALSE; } tsp->write_spifr->status->external_filename = mtrf_strdup(filename); break; } default: { return_err(proc,200,SPNULL,"Internal error"); } } /* now that the file is opened, load the header if it exist, */ /* otherwise alloc an empty header for the user */ switch (tsp->open_mode) { case (SP_mode_read): { /* read the header */ tsp->read_spifr->header = sp_open_header(tsp->read_spifr->waveform->sp_fp,TRUE,&errmsg); if ( tsp->read_spifr->header == HDRNULL ) { free_sphere_t(tsp); return_err(proc,104,SPNULL, rsprintf("Unable to open SPHERE header of file '%s', %s", filename,errmsg)); } /* get the size of the header */ if (! strsame(filename,"-")) { if ((tsp->read_spifr->waveform->header_data_size = sp_file_header_size(filename)) < 0){ free_sphere_t(tsp); return_err(proc,110,SPNULL, rsprintf("Unable to get SPHERE header size of file '%s'", filename)); } } else { if ((tsp->read_spifr->waveform->header_data_size = sp_header_size(tsp->read_spifr->header)) < 0){ free_sphere_t(tsp); return_err(proc,111,SPNULL, rsprintf("Unable to get SPHERE header size of file '%s'", filename)); } } /****** Remove the sample_count field if it's ******/ /****** value is 999999999 and the file is a stream ******/ /****** Added by JGF June 22, 1994 ******/ if (! tsp->read_spifr->status->is_disk_file){ int type, size; SP_INTEGER l_int; if (sp_get_field(tsp->read_spifr->header, SAMPLE_COUNT_FIELD,&type,&size) == 0){ if (sp_get_data(tsp->read_spifr->header,SAMPLE_COUNT_FIELD, (char *)&l_int,&size) == 0){ if (l_int == 999999999){ if (sp_verbose > 10) fprintf(spfp, "Proc %s: file '%s' deleting %s field\n", proc,filename,SAMPLE_COUNT_FIELD); if (sp_delete_field(tsp->read_spifr->header, SAMPLE_COUNT_FIELD) < 0) return_err(proc,112,SPNULL, rsprintf("Unable to delete fake '%s' field", SAMPLE_COUNT_FIELD)); } } } } /****** Correct any out-of-date headers right NOW ******/ if (correct_out_of_date_headers(tsp) != 0){ fprintf(spfp,"Warning: correction of "); fprintf(spfp,"out-of-date headers failed\n"); sp_print_return_status(spfp); } /* duplicate the header for the file interface */ if ((tsp->read_spifr->status->file_header = sp_dup_header(tsp->read_spifr->header)) == HDRNULL){ fprintf(spfp,"Error: sp_open_header unable "); fprintf(spfp,"to dup header for file '%s'\n",filename); free_sphere_t(tsp); return_err(proc,106,SPNULL, rsprintf("Unable to duplicate the SPHERE header of file", filename)); } /* set the default operation settings */ if (sp_set_default_operations(tsp) != 0){ print_return_status(spfp); return_err(proc,107,SPNULL, rsprintf("Unable to interpret the SPHERE header of file '%s'", filename)); } break; } case (SP_mode_write):{ tsp->write_spifr->header = sp_create_header(); if ( tsp->write_spifr->header == HDRNULL ) { free_sphere_t(tsp); return_err(proc,108,SPNULL, rsprintf("Unable to allocate SPHERE header for file '%s'", filename)); } tsp->write_spifr->status->file_header = sp_create_header(); if ( tsp->write_spifr->status->file_header == HDRNULL ) { free_sphere_t(tsp); return_err(proc,109,SPNULL, rsprintf("Unable to allocate hidden SPHE. header for file '%s'", filename)); } } default: ; } /* the file was actually opened for update, so make a temp file, and */ /* duplicate the read in file. */ if (current_mode == SP_mode_update){ SP_FILE *tsp2; SPIFR *tspifr; char *temp_file; char data_mode[100]; temp_file = sptemp(tsp->read_spifr->status->external_filename); if (temp_file == CNULL) return_err(proc,300,SPNULL,"Unable to create temporary filename"); if ((tsp2 = sp_open(temp_file,WRITEMODE)) == SPNULL) { free_sphere_t(tsp); mtrf_free(temp_file); return_err(proc,301,SPNULL, rsprintf("Unable to open temporary file",temp_file)); } sp_set_data_mode(tsp,"SE-ORIG:SBF-ORIG"); /* now copy the header into the update file */ if (sp_copy_header(tsp,tsp2) != 0){ free_sphere_t(tsp); free_sphere_t(tsp2); unlink(temp_file); mtrf_free(temp_file); return_err(proc,302,SPNULL,"Unable to duplicate output header"); } *data_mode = '\0'; /*now set the data mode to match the output format of the read file*/ switch (tsp->read_spifr->status->file_compress){ case SP_wc_shorten: strcat(data_mode,"SE-SHORTEN:"); break; case SP_wc_wavpack: strcat(data_mode,"SE-WAVPACK:"); break; case SP_wc_shortpack: strcat(data_mode,"SE-SHORTPACK:"); break; default: ; } switch (tsp->read_spifr->status->file_sbf){ case SP_sbf_01: strcat(data_mode,"SBF-01"); break; case SP_sbf_10: strcat(data_mode,"SBF-10"); break; case SP_sbf_1: strcat(data_mode,"SBF-1"); break; case SP_sbf_N: strcat(data_mode,"SBF-N"); break; default: ; } if (sp_set_data_mode(tsp2,data_mode) >= 100){ free_sphere_t(tsp); free_sphere_t(tsp2); unlink(temp_file); mtrf_free(temp_file); return_err(proc,303,SPNULL, rsprintf("Unable to set_data_mode '%s' for update file", data_mode)); } /* now merge the two SPFILE pointers into a single structure */ /* and free the residual */ tspifr = tsp->write_spifr; tsp->write_spifr = tsp2->write_spifr; tsp2->write_spifr = tspifr; free_sphere_t(tsp2); mtrf_free(temp_file); tsp->open_mode = current_mode; } /* sp_file_dump(tsp,spfp);*/ if (sp_verbose > 17) sp_file_dump(tsp,spfp); if (sp_verbose > 11) fprintf(spfp,"Proc %s: Returning Sphere-file pointer\n",proc); return_success(proc,0,tsp,"ok"); }
BOOL FileOpen (HWND hWndParent, int nStringResourceID, LPTSTR lpInputFileName) { OPENFILENAME ofn ; TCHAR szFileSpec [256] ; TCHAR szFileTitle [80] ; TCHAR szDialogTitle [80] ; HANDLE hFile ; PERFFILEHEADER FileHeader ; TCHAR aszOpenFilter[LongTextLen] ; int StringLength ; BOOL retCode ; LPTSTR pFileName = NULL ; if (strempty(lpInputFileName)) { dwCurrentDlgID = HC_PM_idDlgFileOpen ; // get the file extension strings LoadString (hInstance, nStringResourceID, aszOpenFilter, sizeof(aszOpenFilter) / sizeof(TCHAR)) ; StringLength = lstrlen (aszOpenFilter) + 1 ; LoadString (hInstance, nStringResourceID+1, &aszOpenFilter[StringLength], sizeof(aszOpenFilter) / sizeof(TCHAR) - StringLength) ; StringLength += lstrlen (&aszOpenFilter[StringLength]) + 1 ; #ifdef ADVANCED_PERFMON // get workspace file extension strings LoadString (hInstance, IDS_WORKSPACEFILE, &aszOpenFilter[StringLength], sizeof(aszOpenFilter) / sizeof(TCHAR) - StringLength) ; StringLength += lstrlen (&aszOpenFilter[StringLength]) + 1 ; LoadString (hInstance, IDS_WORKSPACEFILEEXT, &aszOpenFilter[StringLength], sizeof(aszOpenFilter) / sizeof(TCHAR) - StringLength) ; StringLength += lstrlen (&aszOpenFilter[StringLength]) + 1; #endif // get all file extension strings LoadString (hInstance, IDS_ALLFILES, &aszOpenFilter[StringLength], sizeof(aszOpenFilter) / sizeof(TCHAR) - StringLength) ; StringLength += lstrlen (&aszOpenFilter[StringLength]) + 1 ; LoadString (hInstance, IDS_ALLFILESEXT, &aszOpenFilter[StringLength], sizeof(aszOpenFilter) / sizeof(TCHAR) - StringLength) ; StringLength += lstrlen (&aszOpenFilter[StringLength]) ; // setup the end strings aszOpenFilter[StringLength+1] = aszOpenFilter[StringLength+2] = TEXT('\0') ; strclr (szFileSpec) ; strclr (szFileTitle) ; StringLoad (IDS_FILEOPEN_TITLE, szDialogTitle) ; memset (&ofn, 0, sizeof(OPENFILENAME)) ; ofn.lStructSize = sizeof(OPENFILENAME) ; ofn.hwndOwner = hWndParent ; ofn.hInstance = hInstance; ofn.lpstrTitle = szDialogTitle ; ofn.lpstrFilter = aszOpenFilter ; ofn.nFilterIndex = 1L ; ofn.lpstrFile = szFileSpec; ofn.nMaxFile = sizeof(szFileSpec); ofn.lpstrFileTitle = szFileTitle; ofn.nMaxFileTitle = sizeof(szFileTitle); ofn.Flags = OFN_HIDEREADONLY | OFN_FILEMUSTEXIST | OFN_ENABLEHOOK ; ofn.lpfnHook = (LPOFNHOOKPROC) FileOpenHookProc ; if (!GetOpenFileName(&ofn)) { dwCurrentDlgID = 0 ; return (FALSE) ; } dwCurrentDlgID = 0 ; hFile = FileHandleOpen (szFileSpec) ; pFileName = szFileSpec ; } // NULL lpFileName else { // open the input file hFile = FileHandleOpen (lpInputFileName) ; if (hFile && hFile != INVALID_HANDLE_VALUE && SearchPath (NULL, lpInputFileName, NULL, sizeof(szFileSpec)/sizeof(TCHAR) - 1, szFileSpec, &pFileName)) { pFileName = szFileSpec ; } else { pFileName = NULL ; } } if (!hFile || hFile == INVALID_HANDLE_VALUE) { return (FALSE) ; } if (!FileRead (hFile, &FileHeader, sizeof (FileHeader))) { CloseHandle (hFile) ; if (strempty(lpInputFileName)) { DlgErrorBox (hWndParent, ERR_BAD_SETTING_FILE, pFileName) ; } return (FALSE) ; } //=============================// // Chart File? // //=============================// if (strsame (FileHeader.szSignature, szPerfChartSignature)) { retCode = OpenChart (hWndGraph, hFile, FileHeader.dwMajorVersion, FileHeader.dwMinorVersion, TRUE) ; if (retCode) { ChangeSaveFileName (pFileName, IDM_VIEWCHART) ; } else { goto ErrExit ; } return (retCode) ; } //=============================// // Unknown file type // //=============================// CloseHandle (hFile) ; ErrExit: DlgErrorBox (hWndParent, ERR_BAD_SETTING_FILE, pFileName) ; return (FALSE) ; } // FileOpen
int sp_close(SP_FILE *sp) { char *proc="sp_close " SPHERE_VERSION_STR; char *write_name; char *read_name; SP_INTEGER lint=0, header_size=0, data_size=0; int header_changed=FALSE; SPIFR *spifr; SPSTATUS *w_spstat, *r_spstat; int ret, verify_checksum=FALSE; if (sp_verbose > 10) fprintf(spfp,"Proc %s:\n",proc); if (sp == SPNULL) return_err(proc,100,100,"Null SPFILE pointer"); w_spstat = sp->write_spifr->status; r_spstat = sp->read_spifr->status; write_name = (w_spstat->external_filename == CNULL) ? CNULL : mtrf_strdup(sp->write_spifr->status->external_filename); read_name = (r_spstat->external_filename == CNULL) ? CNULL : mtrf_strdup(r_spstat->external_filename); if (sp->open_mode == SP_mode_update) { if (sp_verbose > 10) fprintf(spfp,"Proc %s: Mode SP_update\n",proc); if (w_spstat->write_occured_flag) { /* if there has been a spwrite, then the waveform is written */ /* as if it were a file opened for write */ /* Step 1: recursively call sp_close, changing the mode to write */ /* Step 2: delete the previous file */ /* Step 3: rename the temporary file */ if (sp_verbose > 15) fprintf(spfp,"Proc %s: Overwriting the original waveform\n", proc); sp->open_mode = SP_mode_write; if ((ret=sp_close(sp)) != 0){ unlink(write_name); if (write_name != CNULL) mtrf_free(write_name); if (read_name != CNULL) mtrf_free(read_name); return_child(proc,int,ret); } unlink(read_name); rename(write_name,read_name); if (write_name != CNULL) mtrf_free(write_name); if (read_name != CNULL) mtrf_free(read_name); return_success(proc,0,0,"ok"); } else { /* the header has been changed and the data mode of the waveform */ /* COULD BE CHANGED the waveform has not been modified in any */ /* way, only the header has changed */ /* Step 1: write the header into the temporary file */ /* Step 2: If the header changed in size OR the waveform */ /* format has changed */ /* A: copy the waveform into the temp file */ /* B: close the files */ /* C: delete the old file in favor of the new file */ /* Else the header has not changed in size. */ /* A: write the header into the original file */ /* B: Close both files */ /* C: delete the temporary file */ FILE *fp; int samples_read, samples_written; /* Step 1: */ spifr = sp->write_spifr; fp = ((spifr->waveform->sp_fp != FPNULL) ? (spifr->waveform->sp_fp) : ((spifr->waveform->sp_fob->fp != FPNULL) ? (spifr->waveform->sp_fob->fp) : FPNULL)); if (sp_verbose > 15) fprintf(spfp, "Proc %s: Writing header to temp file. position %d\n", proc,ftell(fp)); if (fp == FPNULL){ free_sphere_t(sp); unlink(write_name); if (write_name != CNULL) mtrf_free(write_name); if (read_name != CNULL) mtrf_free(read_name); return_err(proc,3000,3000,"Internal Error"); } /* Write the header into the temporary file to compute the size */ /* of the header and then rewind back over the just written header*/ rewind(fp); if (sp_write_header(fp,spifr->status->file_header, &header_size,&data_size) < 0){ free_sphere_t(sp); unlink(write_name); if (write_name != CNULL) mtrf_free(write_name); if (read_name != CNULL) mtrf_free(read_name); return_err(proc,3001,3001, "Unable to update header in file"); } rewind(fp); /* Step 2 - - if the header size or waveform has changed */ if ((sp->read_spifr->waveform->header_data_size != header_size) || (w_spstat->file_encoding != r_spstat->file_encoding) || (w_spstat->file_compress != r_spstat->file_compress) || (w_spstat->file_sbf != r_spstat->file_sbf) || (w_spstat->channels != CHANNELSNULL)){ char *buff; int ns, nc, in_nspb, out_nspb; if (sp_verbose > 15) { fprintf(spfp,"Proc %s: output header and/or",proc); fprintf(spfp,"data has changed, copying file.\n"); fprintf(spfp,"Proc %s: from %d to %d\n",proc, sp->read_spifr->waveform->header_data_size, header_size); } ns = r_spstat->user_sample_count; nc = r_spstat->user_channel_count; in_nspb = r_spstat->user_sample_n_bytes * r_spstat->user_channel_count; out_nspb = w_spstat->user_sample_n_bytes * w_spstat->user_channel_count; if ((buff=mtrf_malloc(nc * in_nspb * 4096)) == CNULL) { free_sphere_t(sp); unlink(write_name); if (write_name != CNULL) mtrf_free(write_name); if (read_name != CNULL) mtrf_free(read_name); return_err(proc,3010,3010, "Unable to malloc transfer buffer space"); } /* A: */ do { sp->open_mode = SP_mode_read; samples_read = sp_read_data(buff,4096,sp); if (samples_read > 0) { sp->open_mode = SP_mode_write; samples_written = sp_write_data(buff,samples_read,sp); if (samples_written != samples_read){ free_sphere_t(sp); unlink(write_name); if (write_name != CNULL) mtrf_free(write_name); if (read_name != CNULL) mtrf_free(read_name); return_err(proc,3012,3012, "Copy of waveform data failed"); } } else { if (sp_eof(sp) == 0) { free_sphere_t(sp); unlink(write_name); if (write_name != CNULL) mtrf_free(write_name); if (read_name != CNULL) mtrf_free(read_name); return_err(proc,3013,3013, "Error: Zero samples read while not at EOF"); } if (sp_error(sp) >= 100) { /* a checksum error occured, close the sp and */ /* delete the temp file */ sp->open_mode = SP_mode_update; sp_print_return_status(spfp); free_sphere_t(sp); unlink(write_name); if (write_name != CNULL) mtrf_free(write_name); if (read_name != CNULL) mtrf_free(read_name); mtrf_free(buff); return_err(proc,3011,3011, "Error copying waveform data"); } } sp->open_mode = SP_mode_update; } while (samples_read > 0); mtrf_free(buff); /* make sure the file is at eof (as if it were opened for */ /* read) */ sp->open_mode = SP_mode_read; if (! sp_eof(sp)){ sp->open_mode = SP_mode_update; free_sphere_t(sp); unlink(write_name); if (write_name != CNULL) mtrf_free(write_name); if (read_name != CNULL) mtrf_free(read_name); return_err(proc,3012,3012,"Error copying waveform data"); } sp->open_mode = SP_mode_write; if ((ret=sp_close(sp)) != 0){ unlink(write_name); if (write_name != CNULL) mtrf_free(write_name); if (read_name != CNULL) mtrf_free(read_name); return_child(proc,int,ret); } /* C: */ unlink(read_name); rename(write_name,read_name); if (write_name != CNULL) mtrf_free(write_name); if (read_name != CNULL) mtrf_free(read_name); return_success(proc,0,0,"ok"); } else { /* A: */ spifr = sp->read_spifr; fp = ((spifr->waveform->sp_fp != FPNULL) ? (spifr->waveform->sp_fp) : ((spifr->waveform->sp_fob->fp != FPNULL) ? (spifr->waveform->sp_fob->fp) : FPNULL)); if (fp == FPNULL) return_err(proc,3002,3002,"Internal Error"); rewind(fp); if (sp_verbose > 15) fprintf(spfp, "Proc %s: header size not changed. position %d\n", proc,ftell(fp)); if (sp_write_header(fp,w_spstat->file_header, &header_size,&data_size) < 0){ free_sphere_t(sp); unlink(write_name); if (write_name != CNULL) mtrf_free(write_name); if (read_name != CNULL) mtrf_free(read_name); return_err(proc,3003,3003, "Unable to update header in file"); } /* B: */ free_sphere_t(sp); /* C: */ unlink(write_name); if (write_name != CNULL) mtrf_free(write_name); if (read_name != CNULL) mtrf_free(read_name); return_success(proc,0,0,"ok"); } } } /* END of update mode file */ if (sp->open_mode == SP_mode_write) { if (sp_verbose > 10) fprintf(spfp, "Proc %s: Mode SP_mode_write\n",proc); spifr = sp->write_spifr; /* flush the data to the file */ if (spifr->status->is_disk_file) fob_fflush(spifr->waveform->sp_fob); /* if the mode is write, update the sample_count and checksum */ /* field if needed. If the checksum field exists, verify it, */ /* and warn if it's not the same */ /************ ONLY UPDATE FIELDS IF THE FILE IS NOT A STREAM *********/ if (spifr->status->is_disk_file){ h_get_field(w_spstat->file_header, SAMPLE_COUNT_FIELD, T_INTEGER, (void *)&lint); if (spifr->waveform->samples_written != lint) { /* then update the field */ lint = (SP_INTEGER) spifr->waveform->samples_written; spifr->status->file_sample_count = lint; /* temporarily reset the write occured flag to allow header */ /* modifications */ w_spstat->write_occured_flag = FALSE; if (sp_h_set_field(sp,SAMPLE_COUNT_FIELD,T_INTEGER,&lint) !=0){ if (write_name != CNULL) mtrf_free(write_name); if (read_name != CNULL) mtrf_free(read_name); free_sphere_t(sp); return_err(proc,200,200,"Unable to update sample_count"); } /* Reset the write occured flag */ w_spstat->write_occured_flag = TRUE; header_changed = TRUE; } if (h_get_field(spifr->status->file_header,SAMPLE_CHECKSUM_FIELD, T_INTEGER,(void *)&lint) != 0){ if (write_name != CNULL) mtrf_free(write_name); if (read_name != CNULL) mtrf_free(read_name); free_sphere_t(sp); return_err(proc,201,201, "Unable to get sample_checksum for file on disk"); } if (lint != spifr->status->file_checksum) { /* then the checksum was just computed, so install it */ lint = (SP_INTEGER)spifr->waveform->checksum; /* temporarily reset the write occured flag to allow header */ /* modifications */ w_spstat->write_occured_flag = FALSE; if (sp_h_set_field(sp,SAMPLE_CHECKSUM_FIELD, T_INTEGER,&lint) >= 100){ if (write_name != CNULL) mtrf_free(write_name); if (read_name != CNULL) mtrf_free(read_name); free_sphere_t(sp); return_err(proc,202,202,"Unable to update checksum"); } /* Reset the write occured flag */ w_spstat->write_occured_flag = TRUE; header_changed = TRUE; } else if (lint != spifr->waveform->checksum) { spifr->waveform->failed_checksum = TRUE; if (write_name != CNULL) mtrf_free(write_name); if (read_name != CNULL) mtrf_free(read_name); free_sphere_t(sp); return_err(proc,203,203, rsprintf("Write verification of checksum failed on file %s", spifr->status->external_filename)); } } /* flush the updated header to the file */ if (header_changed) { FILE *fp; if (! spifr->status->is_disk_file) { if (write_name != CNULL) mtrf_free(write_name); if (read_name != CNULL) mtrf_free(read_name); free_sphere_t(sp); return_err(proc,301,301, "Internal Error, header changed size on write to stdout"); } fp = ((spifr->waveform->sp_fp != FPNULL) ? (spifr->waveform->sp_fp) : ((spifr->waveform->sp_fob->fp != FPNULL) ? (spifr->waveform->sp_fob->fp) : FPNULL)); if (fp == FPNULL) { if (write_name != CNULL) mtrf_free(write_name); if (read_name != CNULL) mtrf_free(read_name); free_sphere_t(sp); return_err(proc,300,300,"Internal Error"); } rewind(fp); if (sp_write_header(fp,spifr->status->file_header, &header_size,&data_size) < 0) { if (write_name != CNULL) mtrf_free(write_name); if (read_name != CNULL) mtrf_free(read_name); free_sphere_t(sp); return_err(proc,204,204,"Unable to update header in file"); } } if ((spifr->status->is_temp_file == FALSE) && fob_is_fp(spifr->waveform->sp_fob)) { /* check to make sure the blocking has not changed */ if (header_changed) if (((data_size + PAD_MULT) / PAD_MULT) != ((spifr->waveform->header_data_size + PAD_MULT) /PAD_MULT)){ if (write_name != CNULL) mtrf_free(write_name); if (read_name != CNULL) mtrf_free(read_name); free_sphere_t(sp); return_err(proc,205,205, "Header size has changed on update"); } } else { if (spifr->status->user_compress == spifr->status->file_compress){ if (fob_flush_to_fp(spifr->waveform->sp_fob, spifr->waveform->sp_fp) != 0){ if (write_name != CNULL) mtrf_free(write_name); if (read_name != CNULL) mtrf_free(read_name); free_sphere_t(sp); return_err(proc,206,206,"Unable to flush data to disk"); } } else { /* do some compression */ FOB *comp_fob; /* 1. rewind the data */ /* 2. alloc FOB to compress into */ /* 3. compress the file */ /* 4. free the allocated FOB */ fob_rewind(spifr->waveform->sp_fob); if ((comp_fob = fob_create(spifr->waveform->sp_fp)) == FOBPNULL) { if (write_name != CNULL) mtrf_free(write_name); if (read_name != CNULL) mtrf_free(read_name); free_sphere_t(sp); return_err(proc,207,207,"Unable to setup for compression"); } spifr->waveform->sp_fp = FPNULL; switch (spifr->status->file_compress){ char message[70]; case SP_wc_shorten: /* optimize the compression */ shorten_set_channel_count(spifr->status->file_channel_count); if (spifr->status->file_encoding == SP_se_ulaw) shorten_set_ftype("au"); else if (spifr->status->file_encoding == SP_se_pcm1) shorten_set_ftype("s8"); else if (spifr->status->file_encoding == SP_se_pcm2) if (spifr->status->file_sbf == SP_sbf_01) shorten_set_ftype("s16lh"); else shorten_set_ftype("s16hl"); if (sp_verbose > 15) shorten_dump_flags(spfp); if(setjmp(exitenv) == 0){ if (shorten_compress(spifr->waveform->sp_fob, comp_fob, message) < 0){ fob_destroy(comp_fob); if (write_name != CNULL) mtrf_free(write_name); if (read_name != CNULL) mtrf_free(read_name); free_sphere_t(sp); return_err(proc,208,208, rsprintf("Shorten Compression Failed - %s", message)); } } else return_err(proc,213,0,"Shorten Compression Aborted"); fob_fflush(comp_fob); break; case SP_wc_wavpack: if(setjmp(exitenv) == 0){ /* optimize the compression */ wavpack_set_progname( "wavpack" ); if (spifr->status->file_channel_count == 1) wavpack_set_monoflg(TRUE); else wavpack_set_monoflg(FALSE); wavpack_set_byteflg(spifr->status->file_sbf ==SP_sbf_1); if (sp_verbose > 15) wavpack_dump_interface(spfp); if (wavpack_pack(spifr->waveform->sp_fob, comp_fob)<0){ fob_destroy(comp_fob); if (write_name != CNULL) mtrf_free(write_name); if (read_name != CNULL) mtrf_free(read_name); free_sphere_t(sp); return_err(proc,209,209, "Wavpack Compression Failed"); } wavpack_free_progname(); fob_fflush(comp_fob); } else { return_err(proc,212,0,"Wavpack Compression Aborted"); } break; case SP_wc_shortpack: return_err(proc,211,211, "Unable to Compress using shortpack\n"); default: if (write_name != CNULL) mtrf_free(write_name); if (read_name != CNULL) mtrf_free(read_name); free_sphere_t(sp); return_err(proc,210,210, "Unable to Compress the requested format\n"); } spifr->waveform->sp_fp = comp_fob->fp; fob_destroy(comp_fob); } } if ((sp->open_mode == SP_mode_write) || (sp->open_mode == SP_mode_update)) if (w_spstat->extra_checksum_verify) verify_checksum = TRUE; } free_sphere_t(sp); /*************************************************/ /* The file is now completely written and closed */ /*************************************************/ /**************************************************/ /* If the write verification is requested, do it */ if (verify_checksum) { if (strsame(write_name,"-")) { if (write_name != CNULL) mtrf_free(write_name); if (read_name != CNULL) mtrf_free(read_name); return_warn(proc,1,1, "Unable to verify checksum, file went to STDOUT"); } if (verify_file_checksum(write_name) != 0){ sp_print_return_status(spfp); if (write_name != CNULL) mtrf_free(write_name); if (read_name != CNULL) mtrf_free(read_name); return_err(proc,1000,1000, "Read Verification of written file failed"); } } if (write_name != CNULL) mtrf_free(write_name); if (read_name != CNULL) mtrf_free(read_name); return_success(proc,0,0,"ok"); }
int diff_header(char *file1, char *file2, int *chg, int *ins, int *del, int verbose, FILE *fp) { FILE *fp1, *fp2; struct header_t *h1, *h2; char *errmsg; int i1, i2, found; *chg = *ins = *del = 0; if (strsame(file1,"-") && strsame(file2,"-")) { fprintf(spfp,"diff_header: Unable to compare Stdin to itself\n"); return(100); } if ((fp1 = (strsame(file1,"-") ? stdin : fopen(file1, "r"))) == FPNULL){ fprintf(spfp,"diff_header: Unable to open file '%s'\n",file1); return(100); } if ((fp2 = (strsame(file2,"-") ? stdin : fopen(file2, "r"))) == FPNULL){ fprintf(spfp,"diff_header: Unable to open file '%s'\n",file2); return(100); } if ((h1 = sp_open_header(fp1,TRUE,&errmsg)) == HDRNULL){ if (verbose) fprintf(fp,"diff_header: Unable to open header for file '%s' - %s\n" ,file1,errmsg); fclose(fp1); fclose(fp2); *chg = *ins = *del = 0x7fff; return(100); } if ((h2 = sp_open_header(fp2,TRUE,&errmsg)) == HDRNULL){ if (verbose) fprintf(fp,"diff_header: Unable to open header for file '%s' - %s\n" ,file2,errmsg); sp_close_header(h1); fclose(fp1); fclose(fp2); *chg = *ins = *del = 0x7fff; return(100); } for (i1=0 ;i1 < h1->fc; i1++) { found=0; for (i2=0 ;i2 < h2->fc; i2++) { if (strsame(h1->fv[i1]->name,h2->fv[i2]->name)) { found=1; if (h1->fv[i1]->type != h2->fv[i2]->type){ if (verbose) fprintf(fp," Changed field '%s' type %d -> %d\n", h1->fv[i1]->name,h1->fv[i1]->type, h2->fv[i2]->type); *chg += 1; continue; } else { if (! strsame(h1->fv[i1]->data,h2->fv[i2]->data)){ if(strsame(h1->fv[i1]->name,SAMPLE_CODING_FIELD) && (strncmp(h1->fv[i1]->data,h2->fv[i2]->data,20)==0)) ; else { if (verbose){ fprintf(fp," Changed field '%s' ", h1->fv[i1]->name); fprintf(fp,"value %s -> %s\n", h1->fv[i1]->data,h2->fv[i2]->data); } *chg += 1; } } continue; } } } if (found == 0){ if (verbose) fprintf(fp," Deleted field %s\n", h1->fv[i1]->name); *del += 1; } } for (i2=0 ;i2 < h2->fc; i2++) { found=0; for (i1=0 ;found==0 && i1 < h1->fc; i1++) { if (strsame(h1->fv[i1]->name,h2->fv[i2]->name)) found=1; } if (found == 0){ if (verbose) fprintf(fp," Inserted field %s\n", h2->fv[i2]->name); *ins += 1; } } sp_close_header(h1); sp_close_header(h2); if (fp1 != stdin) fclose(fp1); if (fp2 != stdin) fclose(fp2); return(0); }
int diff_data(char *file1, char *file2, int verbose, FILE *fp) { FILE *fp1, *fp2; struct header_t *h1, *h2; char c1, c2, *errmsg; int chr=0; if (strsame(file1,"-") && strsame(file2,"-")) { fprintf(spfp,"diff_data: Unable to compare Stdin to itself\n"); return(100); } if ((fp1 = (strsame(file1,"-") ? stdin : fopen(file1, "r"))) == FPNULL){ fprintf(spfp,"diff_data: Unable to open file '%s'\n",file1); return(100); } if ((fp2 = (strsame(file2,"-") ? stdin : fopen(file2, "r"))) == FPNULL){ fprintf(spfp,"diff_data: Unable to open file '%s'\n",file2); return(100); } if ((h1 = sp_open_header(fp1,TRUE,&errmsg)) == HDRNULL){ if (verbose) fprintf(fp,"diff_data: Unable to open SPHERE header for file %s\n" ,file1); return(100); } if ((h2 = sp_open_header(fp2,TRUE,&errmsg)) == HDRNULL){ if (verbose) fprintf(fp,"diff_data: Unable to open SPHERE header for file %s\n" ,file2); return(100); } /* make Sure the sample byte_formats are the same before proceeding */ { char *h1_sbf, *h2_sbf; int n, type, size; n = sp_get_field( h1, "sample_byte_format", &type, &size ); if ( n < 0 ) { fprintf(fp,"diff_data: Can't get sample_byte_format for file %s\n", file1); return(100); } if ((h1_sbf = (char *)mtrf_malloc( size + 1 )) == CNULL ){ fprintf(fp,"diff_data: malloc failed for sbf string\n"); return(100); } if ((n = sp_get_data( h1, "sample_byte_format", h1_sbf, &size )) != 0){ fprintf(fp,"diff_data: Can't Load sample_byte_format for file %s\n", file1); mtrf_free(h1_sbf); return(100); } h1_sbf[size] = '\0'; n = sp_get_field( h2, "sample_byte_format", &type, &size ); if ( n < 0 ) { fprintf(fp,"diff_data: Can't get sample_byte_format for file %s\n", file2); mtrf_free(h1_sbf); return(100); } if ((h2_sbf = (char *)mtrf_malloc( size + 1 )) == CNULL ){ fprintf(fp,"diff_data: malloc failed for sbf string\n"); mtrf_free(h1_sbf); return(100); } if ((n = sp_get_data( h2, "sample_byte_format", h2_sbf, &size )) != 0){ fprintf(fp,"diff_data: Can't Load sample_byte_format for file %s\n", file2); mtrf_free(h1_sbf); mtrf_free(h2_sbf); return(100); } h2_sbf[size] = '\0'; if (! strsame(h1_sbf,h2_sbf)){ mtrf_free(h1_sbf); mtrf_free(h2_sbf); if (verbose) fprintf(fp,"diff_data: Sphere files %s and %s differ in their sample_byte_format\n", file1,file2); fclose(fp1); fclose(fp2); return(1000); } /* The check passed, continue the test */ mtrf_free(h1_sbf); mtrf_free(h2_sbf); } do { c1 = fgetc(fp1); c2 = fgetc(fp2); if (c1 != c2){ if (verbose) fprintf(fp,"diff_data: Sphere files %s and %s differ at character %d\n", file1,file2,chr); fclose(fp1); fclose(fp2); return(100); } chr ++; } while (!feof(fp1)); if (!feof(fp2)){ sp_close_header(h1); sp_close_header(h2); fclose(fp1); fclose(fp2); return(100); } sp_close_header(h1); sp_close_header(h2); if (fp1 != stdin) fclose(fp1); if (fp2 != stdin) fclose(fp2); return(0); }
/** * tests all helper functions */ static char * test_helpers() { Logo input; char tmp[VAR_LENGTH+1], str[LINE_LENGTH]; char * trimmed; int ret, i; float output; printf("Testing %s\n", __FUNCTION__); /* test get_var() */ input = create_logo(0); /* this is essentially set_var("A", input->vars, 10); */ input->vars[0].data = 10; input->vars[0].used = 1; /* try to get A */ ret = get_var("A", input->vars, &output); mu_assert("error, ret != 0", ret == 0); mu_assert("error, A != 10", output == 10); /* try to get B which is not initialised */ ret = get_var("B", input->vars, &output); mu_assert("error, ret != VAR_ERR", ret == VAR_ERR); /* test set_var() */ set_var("A", input->vars, 20); set_var("B", input->vars, 40); mu_assert("error, A != 20", input->vars[0].data == 20.0); mu_assert("error, B != 40", input->vars[1].data == 40.0); /* setting the var should have flagged this var as used */ mu_assert("error, B is not initialised", input->vars[0].used == 1); /* test is_var() from A-Z */ for (i='A'; i<='Z'; i++) { tmp[0] = i; tmp[1] = '\0'; ret = is_var(tmp); mu_assert("error, ret != 1", ret == 1); } /* test bogus inputs */ /* small letter */ tmp[0] = 'a'; ret = is_var(tmp); mu_assert("error, ret != 0", ret == 0); /* number */ tmp[0] = '1'; ret = is_var(tmp); mu_assert("error, ret != 0", ret == 0); /* test is_op */ tmp[0] = '+'; ret = is_op(tmp); mu_assert("error, ret != 1", ret == 1); tmp[0] = '-'; ret = is_op(tmp); mu_assert("error, ret != 1", ret == 1); tmp[0] = '*'; ret = is_op(tmp); mu_assert("error, ret != 1", ret == 1); tmp[0] = '/'; ret = is_op(tmp); mu_assert("error, ret != 1", ret == 1); /* test bogus inputs */ tmp[0] = '='; ret = is_op(tmp); mu_assert("error, ret != 0", ret == 0); tmp[0] = '^'; ret = is_op(tmp); mu_assert("error, ret != 0", ret == 0); tmp[0] = '$'; ret = is_op(tmp); mu_assert("error, ret != 0", ret == 0); /* test trim_space() */ strcpy(str, "\t\tFD 30 \t\t "); trimmed = trim_space(str); mu_assert("error, trimmed != \"FD 30\"", strsame(trimmed, "FD 30")); strcpy(str, " \t \tDO A FROM 1 TO 8 { \t\t "); trimmed = trim_space(str); mu_assert("error, trimmed != \"DO A FROM 1 TO 8 {\"", strsame(trimmed, "DO A FROM 1 TO 8 {")); tear_down(input); return 0; }