OsStatus ForwardRules::getRouteTo(UtlString& RouteToString, bool& authRequired, TiXmlNode* nodeWithRouteToChild) { OsStatus currentStatus = OS_FAILED; nodeWithRouteToChild->ToElement(); TiXmlNode* routeToNode = NULL; TiXmlNode* routeToText = NULL; //get the user text value from it routeToNode = nodeWithRouteToChild->FirstChild(XML_TAG_ROUTETO); if(routeToNode) { if(routeToNode && routeToNode->Type() != TiXmlNode::ELEMENT) { return currentStatus; } TiXmlElement* routeToElement = routeToNode->ToElement(); const char* authRequiredPtr = routeToElement->Attribute(XML_ATT_AUTHREQUIRED); //set the authRequired attribute authRequired=getYN(authRequiredPtr, false) ; //defaults to false RouteToString.remove(0); routeToText = routeToElement->FirstChild(); if(routeToText && routeToText->Type() == TiXmlNode::TEXT) { TiXmlText* routeTo = routeToText->ToText(); if (routeTo) { RouteToString.append(routeTo->Value()); } } // TinyXML compresses white space, so an all white space element becomes // zero length, but just in case, let's strip it ourselves. RouteToString.strip(UtlString::both); if (RouteToString.length() > 0) { // The route is not empty. Declare success currentStatus = OS_SUCCESS; } else if (authRequired) { // The Route can be empty, as long as authRequired is set. // This means just route to the authProxy. currentStatus = OS_SUCCESS; } else { // Empty or missing route, and no authRequired...that's not allowed. currentStatus = OS_FAILED; } } return currentStatus; }
int licence_to_kill(void) { if (data_on_disk && !(defined_format & CLEAR_DISK)) { if (force_f == ASK) { force_banner(); printf("\aAbout to destroy all files on drive %c!\n\a" "Continue (Y/N) ? ", drive); getYN(); } if (force_f == NO) { if (verbose > 0) printf("Operation aborted\n"); return 0; } } data_on_disk = 0; /* Consider there is no longer data on disk */ return 1; }
static int getCommands (void) { paramLetters (); do { printf ("Command: "); getInput (); switch (inputBuffer[0]) { case 0: break; case 't': do { printf ("Enter the name of a table: "); getInput (); strcpy (table, inputBuffer); } while ((validTable = lou_getTable (table)) == NULL); break; case 'r': if (validTable == NULL) { printf ("You must enter a valid table name.\n"); inputBuffer[0] = 0; } break; case 'm': printf ("Reset mode"); if (getYN ()) mode = 0; printf ("No contractions"); mode |= getYN (); printf ("Computer braille at cursor"); mode |= 2 * getYN (); printf ("Dots input and output"); mode |= 4 * getYN (); printf ("8-dot computer braille"); mode |= 8 * getYN (); printf ("Pass1 only"); mode |= 16 * getYN (); break; case 'l': printf ("Do you want to test input and output lengths"); showSizes = getYN (); if (!showSizes) { outputSize = BUFSIZE; break; } printf ("Enter a maximum output size: "); getInput (); outputSize = atoi (inputBuffer); if (outputSize < 0 || outputSize > BUFSIZE) { printf ("Output size must be from 0 tu %d.\n", BUFSIZE); outputSize = BUFSIZE; showSizes = 0; } break; case 'c': printf ("Enter a cursor position: "); getInput (); enteredCursorPos = atoi (inputBuffer); if (enteredCursorPos < -1 || enteredCursorPos > outputSize) { printf ("Cursor position must be from -1 to %d.\n", outputSize); enteredCursorPos = -1; } break; case 'e': printf ("(Enter an x to cancel emphasis.)\n"); printf ("Enter an emphasis string: "); getInput (); strcpy (enteredEmphasis, inputBuffer); break; case 's': printf ("(Enter an x to cancel spacing.)\n"); printf ("Enter a spacing string: "); getInput (); strcpy (enteredSpacing, inputBuffer); break; case 'h': printf ("Commands: action\n"); printf ("(t)able: Enter a table name\n"); printf ("(r)un: run the translation/back-translation loop\n"); printf ("(m)ode: Enter a mode parameter\n"); printf ("(c)ursor: Enter a cursor position\n"); printf ("(e)mphasis: Enter an emphasis string\n"); printf ("(s)pacing: Enter a spacing string\n"); printf ("(h)elp: print this page\n"); printf ("(q)uit: leave the program\n"); printf ("(f)orward-only: do only forward translation\n"); printf ("(b)ack-only: do only back-translation\n"); printf ("show-(p)ositions: show input and output positions\n"); printf ("m(i)nimal: test translator and back-translator with minimal parameters\n"); printf ("test-(l)engths: test accuracy of returned lengths\n"); printf ("\n"); paramLetters (); break; case 'q': lou_free(); exit (EXIT_SUCCESS); case 'f': printf ("Do only forward translation"); forwardOnly = getYN (); break; case 'b': printf ("Do only backward translation"); backOnly = getYN (); break; case 'p': printf ("Show input and output positions"); showPositions = getYN (); break; case 'i': printf ("Test translation/back-translation loop with minimal parameters"); minimalist = getYN (); break; default: printf ("Bad choice.\n"); break; } if (forwardOnly && backOnly) printf ("You cannot specify both forward-only and backward-only translation.\n"); } while (inputBuffer[0] != 'r'); return 1; }
int main( int args, char** argv ) { #ifdef TEST_MODE printf("DEBUG: checking arguments...\n"); #endif if( args<4 ) usage(); int useDblFlag; if( !strcmp(argv[3], "-f") ) useDblFlag = 0; else if( !strcmp(argv[3], "-d") ) useDblFlag = 1; else usage(); #ifdef TEST_MODE printf("DEBUG: reading file...\n"); #endif FILE *inFile = fopen(argv[1], "r"); if( inFile==NULL ) { fprintf(stderr, "Could not read '%s'.\n", argv[1]); exit(1); } #ifdef TEST_MODE printf("DEBUG: checking if write file exists...\n"); #endif // See if write-file exists FILE *outFile = fopen(argv[2], "r"); if( outFile!=NULL ){ #ifdef TEST_MODE printf("DEBUG: closing file...\n"); #endif fclose(outFile); #ifdef TEST_MODE printf("DEBUG: querying user...\n"); #endif printf("Overwrite file '%s'? (y/n): ", argv[2]); if( getYN()=='n' ) return 0; } #ifdef TEST_MODE printf("DEBUG: opening write file...\n"); #endif outFile = fopen(argv[2], "wb"); if( outFile==NULL ) { fprintf(stderr, "Could not open '%s' for writing.\n", argv[2]); exit(1); } #ifdef TEST_MODE printf("DEBUG: fetching infile character 1...\n"); #endif char c = fgetc(inFile); while( c!=EOF ) { // Check for number #ifdef TEST_MODE printf("DEBUG: see if input is a value\n"); #endif if( isNum(c) ) { // Store number string in 'value' char value[64]; int i = 0; do { // Check for size if( i>=sizeof(value)-1 ) { value[i++] = '\0'; fprintf(stderr, "Unable to parse data - missing delimiters: '%s'\n", value); exit(1); } value[i++] = c; c = fgetc(inFile); } while( isNum(c) ); value[i++] = '\0'; // Determine if number is integer (4-bytes max in this version) or float type #ifdef TEST_MODE printf("DEBUG: check for integer/float type\n"); #endif char* iEndPtr; char* dEndPtr; unsigned long iConv = (unsigned long) strtol(value, &iEndPtr, 10); float dConv = strtod(value, &dEndPtr); if( iEndPtr==value+i-1 ) { #ifdef TEST_MODE printf("DEBUG: store integer value\n"); #endif /// TODO /// test this unsigned char da[8]; // Value is an int if( isBigEndian() ) endianSwapInt32(dConv, da); else getBytesInt32(dConv, da); // Write to file in binary format int i; for( i = 0; i<4; i++ ) if( fputc(da[i], outFile)==EOF ) { fprintf(stderr, "Unable to write to file: '%s'\n", argv[2]); exit(1); } } else if( dEndPtr==value+i-1 ) { if( useDblFlag ) { #ifdef TEST_MODE printf("DEBUG: store float value\n"); #endif char da[8]; // Value is a float if( isBigEndian() ) endianSwapfloat(dConv, da); else getBytesfloat(dConv, da); // Write to file in binary format int i; for( i = 0; i<8; i++ ) if( fputc(da[i], outFile)==EOF ) { fprintf(stderr, "Unable to write to file: '%s'\n", argv[2]); exit(1); } } else { #ifdef TEST_MODE printf("DEBUG: store float value as a float\n"); #endif char da[4]; // Value is a float if( isBigEndian() ) endianSwapFloat((float) dConv, da); else getBytesFloat((float) dConv, da); // Write to file in binary format int i; for( i = 0; i<4; i++ ) if( fputc(da[i], outFile)==EOF ) { fprintf(stderr, "Unable to write to file: '%s'\n", argv[2]); exit(1); } } } else { fprintf(stderr, "Unable to parse data - value is not a valid int or float: '%s'\n", value); exit(1); } } // Make sure delimiters are plausible #ifdef TEST_MODE printf("DEBUG: check for eof\n"); #endif if( c==EOF ) break; #ifdef TEST_MODE printf("DEBUG: test for delimiter\n"); #endif if( c!=' ' && !iscntrl(c) && !ispunct(c) ) { char str[64]; str[0] = c; str[1] = '\0'; fgets(str+1, sizeof(str)-1, inFile); fprintf(stderr, "Unable to parse data - string is not a valid int or float: '%s'\n", str); exit(1); } #ifdef TEST_MODE printf("DEBUG: input next character in file\n"); #endif c = fgetc(inFile); } #ifdef TEST_MODE printf("DEBUG: closing files\n"); #endif fclose(inFile); fclose(outFile); return 0; }