boolean getfsfile ( const ptrfilespec fs, bigstring bsfile ) { // // 2007-08-01 creedon: check FSRefGetNameStr255 return false if not true // // 2006-06-18 creedon: for Mac, FSRef-ized // #ifdef MACVERSION macgetfilespecnameasbigstring ( fs, bsfile ); if ( stringlength ( bsfile ) > 0 ) return ( true ); long vnum; getfsvolume ( fs, &vnum ); return ( filegetvolumename ( vnum, bsfile ) ); #endif #ifdef WIN95VERSION lastword ((ptrstring) fs -> fullSpecifier, '\\', bsfile); return (true); #endif } // getfsfile
void testcases() { int i,check,len1; char *a; for(i=0;i<11;i++) { a=lastword(testDB[i].input); check=a_cmp(a,testDB[i].output); if(check==0) printf("passed\n"); else printf("failed\n"); free(a); } }
int main( ) { /* upcase() && lowcase() */ { char foo[64]; sprintf(foo, "foobar"); printf("Before case-conversion: '%s'\n", foo); upcase(foo); printf("After upcase: '%s'\n", foo); lowcase(foo); printf("After lowcase: '%s'\n", foo); sprintf(foo, "unicode öä ¹²³"); printf("Before case-conversion: '%s'\n", foo); upcase(foo); printf("After upcase: '%s'\n", foo); lowcase(foo); printf("After lowcase: '%s'\n", foo); } /* randname() */ { char foo[64]; int i, j; #define LEN 8 for (i = 0; i < 2; i++) { switch (i) { case 0: sprintf(foo, "user"); break; case 1: sprintf(foo, "username"); break; } printf("randname: starting with '%s' (len = %d)\n", foo, LEN); for (j = 0; j < LEN * 2; j++) { randname(foo, LEN, '#'); printf("round %02d: '%s'\n", j, foo); } } printf("Generating random stuff:\n"); for (i = 0; i < 4; i++) { foo[0] = '\0'; randname(foo, LEN, '#'); printf("round %d: '%s'\n", i, foo); } } /* pos() && lastpos() */ { char foo[64]; sprintf(foo, "There is no greater power in the universe than " "the need for freedom."); printf("String: '%s'\n", foo); printf("First occurance of 'o' is at %d\n", pos(foo, 'o')); printf("Last occurance of 'o' is at %d\n", lastpos(foo, 'o')); } /* nextword() && lastword() */ { char foo[64]; char *ptr; sprintf(foo, "There is no greater power in the universe than " "the need for freedom."); printf("Words (after the first one):\n"); ptr = nextword(foo); while (ptr != NULL) { printf("'%s'\n", ptr); ptr = nextword(ptr); } printf("Last word: '%s'\n", lastword(foo)); } /* get_short_localtime() && get_timestamp() */ { time_t t; t = rand(); printf("Some timestamps:\n"); printf("Localtime: '%s'\n", get_short_localtime()); printf("Long: '%s'\n", get_timestamp(NULL, TIMESTAMP_LONG)); printf("Short: '%s'\n", get_timestamp(NULL, TIMESTAMP_SHORT)); printf("Abritary: '%s'\n", get_timestamp(&t, TIMESTAMP_LONG)); } return 0; }
void readline(shell_struct *shell) { int i; int end = 0; /*stoppe la saisie lorsqu'il vaut 1*/ int cur_col = 0; /*dans le terminal, indique la position du pointeur*/ struct winsize ws; ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws); int colonnes = ws.ws_col; cur_col = shellPrompt(0); fflush(stdout); printf("\033[s"); struct termios oldt; if (tcgetattr(0, &oldt) != 0) { perror("Erreur tcget"); } struct termios newt = oldt; cfmakeraw(&newt); /* On change la structure termios default, on ajout un retour chariot a chaque newline detecté */ //newt.c_oflag |= (ONLCR | OPOST); if (tcsetattr(0, TCSANOW, &newt) != 0) { perror("Erreur tcset"); } char *com_hist; int count = 0;/*sauvegarde le nombre de char dans le buffer*/ int pos = 0;/*position du curseur dans le buffer buf*/ /*variables pour la tabulation*/ struct tab tabu; init_tab(&tabu); shell->buf[count] = '\0'; do { int t, m; int c = getbigchar(); switch (c) { case 1: /*C^a*/ while (pos > 0) { move_left(&pos,&cur_col,colonnes); } break; case 3: /*C^c*/ shell->buf[0] = '\0'; break; case 4: /*C^D*/ shell->end_b = 1; end = 1; shell->buf[0] = '\n'; break; case 5: /*C^e*/ while (pos != count) { move_right(&pos,&cur_col,colonnes,count); } break; case 9:/*TAB autocompletion */ tabu.tab = 1; /*tab est pressé pour la première fois*/ if (tabu.noccur == 0){ /*on récupère le dernier mot*/ tabu.lw = lastword(shell->buf, &(shell->buf[pos]), &(tabu.after_com), ' '); /*on sauvegarde la position*/ tabu.save_pos = pos - strlen(tabu.lw); } /*on efface*/ while( pos > tabu.save_pos){ move_left(&pos,&cur_col,colonnes); del_char(&pos, &cur_col, colonnes, &count, shell); } ++tabu.noccur; tabu.suggest = look_up_command(tabu.lw, tabu.noccur, tabu.after_com); if (!strncmp(tabu.suggest, "",1)){ tabu.noccur = 1; tabu.suggest = tabu.lw; /*on reprend le mot de base*/ } /*on insère*/ i = 0; while (tabu.suggest[i] != '\0') { insert_char(&pos, &cur_col, colonnes, &count, shell, tabu.suggest[i]); i++; } break; case 11:/*^Ck*/ strncpy(shell->save_buf, &shell->buf[pos], count - pos); shell->save_buf[(count + 1) - pos] = '\0'; while(pos != count) { del_char(&pos,&cur_col,colonnes,&count,shell); } break; case 13:/*Enter*/ end = 1; while (pos != count) { move_right(&pos,&cur_col,colonnes,count); } strncmp(shell->buf, "\0", 1) ? insert_new_cmd(shell->buf) : 0; shell->buf[pos] = '\0'; break; case 25:/*C^y*/ i = 0; while (shell->save_buf[i] != '\0') { insert_char(&pos, &cur_col, colonnes, &count, shell, shell->save_buf[i]); i++; } break; case 2: /*C^b*/ case KLEFT: move_left(&pos, &cur_col, colonnes); break; case 6:/*C^f*/ case KRIGHT: move_right(&pos, &cur_col, colonnes, count); break; case KUP:/*historique -*/ if (!is_empty_hist()){ printf("\033[u"); printf("\033[K"); cur_col = shellPrompt(0); com_hist = get_prev_cmd(); printf("%s", com_hist); strncpy(shell->buf, com_hist, strlen(com_hist) + 1); cur_col += strlen(com_hist); count = strlen(com_hist); pos = count; } break; case KDOWN:/*historique +*/ if (!is_empty_hist()){ printf("\033[u"); printf("\033[K"); cur_col = shellPrompt(0); com_hist = get_next_cmd(); printf("%s", com_hist); strncpy(shell->buf, com_hist, strlen(com_hist) + 1); cur_col += strlen(com_hist); count = strlen(com_hist); pos = count; } break; case KDEL: /* Touche suppr */ del_char(&pos,&cur_col,colonnes,&count,shell); break; case 127: /* Touche retour (del) */ tabu.noccur = 0; if (pos == 0) { break; } if (pos < count) { for (i = pos - 1; i < count; i++) { shell->buf[i] = shell->buf[i + 1]; } } else { shell->buf[pos - 1] = '\0'; } if (cur_col > 0) { printf("\033[D"); cur_col--; } else { printf("\033[A\033[%dC", colonnes - 1); cur_col = colonnes - 1; } count--; pos--; printf("%s ", &shell->buf[pos]); t = count - pos + 1; m = (t + cur_col - 1) / colonnes; if (m > 0) { printf("\033[%dA", m); } t -= m * colonnes; if (t > 0) { printf("\033[%dD", t); } else if (t < 0) { printf("\033[%dC", -t); } break; default: if (tabu.tab){ tabu.noccur = 0; } insert_char(&pos, &cur_col, colonnes, &count, shell, c); break; } fflush(stdout); } while (!end); if (tcsetattr(0, TCSANOW, &oldt) != 0) { perror("erreur tcset"); } printf("\n"); }
void dviRenderer::draw_part(double current_dimconv, bool is_vfmacro) { #ifdef DEBUG_RENDER kDebug(kvs::dvi) << "draw_part"; #endif qint32 RRtmp=0, WWtmp=0, XXtmp=0, YYtmp=0, ZZtmp=0; quint8 ch; currinf.fontp = NULL; currinf.set_char_p = &dviRenderer::set_no_char; int last_space_index = 0; bool space_encountered = false; bool after_space = false; for (;;) { space_encountered = false; ch = readUINT8(); if (ch <= (unsigned char) (SETCHAR0 + 127)) { (this->*currinf.set_char_p)(ch, ch); } else if (FNTNUM0 <= ch && ch <= (unsigned char) (FNTNUM0 + 63)) { currinf.fontp = currinf.fonttable->value(ch - FNTNUM0); if (currinf.fontp == NULL) { errorMsg = i18n("The DVI code referred to font #%1, which was not previously defined.", ch - FNTNUM0); return; } currinf.set_char_p = currinf.fontp->set_char_p; } else { qint32 a, b; switch (ch) { case SET1: case PUT1: (this->*currinf.set_char_p)(ch, readUINT8()); break; case SETRULE: if (is_vfmacro == false) { word_boundary_encountered = true; line_boundary_encountered = true; } /* Be careful, dvicopy outputs rules with height = 0x80000000. We don't want any SIGFPE here. */ a = readUINT32(); b = readUINT32(); b = ((long) (b * current_dimconv)); if (a > 0 && b > 0) { int h = ((int) ROUNDUP(((long) (a * current_dimconv)), shrinkfactor * 65536)); int w = ((int) ROUNDUP(b, shrinkfactor * 65536)); if (colorStack.isEmpty()) foreGroundPainter->fillRect( ((int) ((currinf.data.dvi_h) / (shrinkfactor * 65536))), currinf.data.pxl_v - h + 1, w?w:1, h?h:1, globalColor ); else foreGroundPainter->fillRect( ((int) ((currinf.data.dvi_h) / (shrinkfactor * 65536))), currinf.data.pxl_v - h + 1, w?w:1, h?h:1, colorStack.top() ); } currinf.data.dvi_h += b; break; case PUTRULE: if (is_vfmacro == false) { word_boundary_encountered = true; line_boundary_encountered = true; } a = readUINT32(); b = readUINT32(); a = ((long) (a * current_dimconv)); b = ((long) (b * current_dimconv)); if (a > 0 && b > 0) { int h = ((int) ROUNDUP(a, shrinkfactor * 65536)); int w = ((int) ROUNDUP(b, shrinkfactor * 65536)); if (colorStack.isEmpty()) foreGroundPainter->fillRect( ((int) ((currinf.data.dvi_h) / (shrinkfactor * 65536))), currinf.data.pxl_v - h + 1, w?w:1, h?h:1, globalColor ); else foreGroundPainter->fillRect( ((int) ((currinf.data.dvi_h) / (shrinkfactor * 65536))), currinf.data.pxl_v - h + 1, w?w:1, h?h:1, colorStack.top() ); } break; case NOP: break; case BOP: if (is_vfmacro == false) { word_boundary_encountered = true; line_boundary_encountered = true; } command_pointer += 11 * 4; currinf.data.dvi_h = 1200 << 16; // Reminder: DVI-coordinates start at (1",1") from top of page currinf.data.dvi_v = 1200; currinf.data.pxl_v = int(currinf.data.dvi_v/shrinkfactor); currinf.data.w = currinf.data.x = currinf.data.y = currinf.data.z = 0; break; case EOP: // Check if we are just at the end of a virtual font macro. if (is_vfmacro == false) { // This is really the end of a page, and not just the end // of a macro. Mark the end of the current word. word_boundary_encountered = true; line_boundary_encountered = true; // Sanity check for the dvi-file: The DVI-standard asserts // that at the end of a page, the stack should always be // empty. if (!stack.isEmpty()) { kDebug(kvs::dvi) << "DRAW: The stack was not empty when the EOP command was encountered."; errorMsg = i18n("The stack was not empty when the EOP command was encountered."); return; } } return; case PUSH: stack.push(currinf.data); break; case POP: if (stack.isEmpty()) { errorMsg = i18n("The stack was empty when a POP command was encountered."); return; } else currinf.data = stack.pop(); word_boundary_encountered = true; line_boundary_encountered = true; break; case RIGHT1: case RIGHT2: case RIGHT3: case RIGHT4: RRtmp = readINT(ch - RIGHT1 + 1); // A horizontal motion in the range 4 * font space [f] < h < // font space [f] will be treated as a kern that is not // indicated in the printouts that DVItype produces between // brackets. We allow a larger space in the negative // direction than in the positive one, because TEX makes // comparatively large backspaces when it positions // accents. (comments stolen from the source of dvitype) if ((is_vfmacro == false) && (currinf.fontp != 0) && ((RRtmp >= currinf.fontp->scaled_size_in_DVI_units/6) || (RRtmp <= -4*(currinf.fontp->scaled_size_in_DVI_units/6))) && (currentlyDrawnPage->textBoxList.size() > 0)) { //currentlyDrawnPage->textBoxList[currentlyDrawnPage->textBoxList.size()-1].text += ' '; space_encountered = true; } currinf.data.dvi_h += ((long) (RRtmp * current_dimconv)); break; case W1: case W2: case W3: case W4: WWtmp = readINT(ch - W0); currinf.data.w = ((long) (WWtmp * current_dimconv)); case W0: if ((is_vfmacro == false) && (currinf.fontp != 0) && ((WWtmp >= currinf.fontp->scaled_size_in_DVI_units/6) || (WWtmp <= -4*(currinf.fontp->scaled_size_in_DVI_units/6))) && (currentlyDrawnPage->textBoxList.size() > 0) ) { //currentlyDrawnPage->textBoxList[currentlyDrawnPage->textBoxList.size()-1].text += ' '; space_encountered = true; } currinf.data.dvi_h += currinf.data.w; break; case X1: case X2: case X3: case X4: XXtmp = readINT(ch - X0); currinf.data.x = ((long) (XXtmp * current_dimconv)); case X0: if ((is_vfmacro == false) && (currinf.fontp != 0) && ((XXtmp >= currinf.fontp->scaled_size_in_DVI_units/6) || (XXtmp <= -4*(currinf.fontp->scaled_size_in_DVI_units/6))) && (currentlyDrawnPage->textBoxList.size() > 0)) { //currentlyDrawnPage->textBoxList[currentlyDrawnPage->textBoxList.size()-1].text += ' '; space_encountered = true; } currinf.data.dvi_h += currinf.data.x; break; case DOWN1: case DOWN2: case DOWN3: case DOWN4: { qint32 DDtmp = readINT(ch - DOWN1 + 1); if ((is_vfmacro == false) && (currinf.fontp != 0) && (abs(DDtmp) >= 5*(currinf.fontp->scaled_size_in_DVI_units/6)) && (currentlyDrawnPage->textBoxList.size() > 0)) { word_boundary_encountered = true; line_boundary_encountered = true; space_encountered = true; if (abs(DDtmp) >= 10*(currinf.fontp->scaled_size_in_DVI_units/6)) currentlyDrawnPage->textBoxList[currentlyDrawnPage->textBoxList.size()-1].text += '\n'; } currinf.data.dvi_v += ((long) (DDtmp * current_dimconv))/65536; currinf.data.pxl_v = int(currinf.data.dvi_v/shrinkfactor); } break; case Y1: case Y2: case Y3: case Y4: YYtmp = readINT(ch - Y0); currinf.data.y = ((long) (YYtmp * current_dimconv)); case Y0: if ((is_vfmacro == false) && (currinf.fontp != 0) && (abs(YYtmp) >= 5*(currinf.fontp->scaled_size_in_DVI_units/6)) && (currentlyDrawnPage->textBoxList.size() > 0)) { word_boundary_encountered = true; line_boundary_encountered = true; space_encountered = true; if (abs(YYtmp) >= 10*(currinf.fontp->scaled_size_in_DVI_units/6)) currentlyDrawnPage->textBoxList[currentlyDrawnPage->textBoxList.size()-1].text += '\n'; } currinf.data.dvi_v += currinf.data.y/65536; currinf.data.pxl_v = int(currinf.data.dvi_v/shrinkfactor); break; case Z1: case Z2: case Z3: case Z4: ZZtmp = readINT(ch - Z0); currinf.data.z = ((long) (ZZtmp * current_dimconv)); case Z0: if ((is_vfmacro == false) && (currinf.fontp != 0) && (abs(ZZtmp) >= 5*(currinf.fontp->scaled_size_in_DVI_units/6)) && (currentlyDrawnPage->textBoxList.size() > 0)) { word_boundary_encountered = true; line_boundary_encountered = true; space_encountered = true; if (abs(ZZtmp) >= 10*(currinf.fontp->scaled_size_in_DVI_units/6)) currentlyDrawnPage->textBoxList[currentlyDrawnPage->textBoxList.size()-1].text += '\n'; } currinf.data.dvi_v += currinf.data.z/65536; currinf.data.pxl_v = int(currinf.data.dvi_v/shrinkfactor); break; case FNT1: case FNT2: case FNT3: currinf.fontp = currinf.fonttable->value(readUINT(ch - FNT1 + 1)); if (currinf.fontp == NULL) { errorMsg = i18n("The DVI code referred to a font which was not previously defined."); return; } currinf.set_char_p = currinf.fontp->set_char_p; break; case FNT4: currinf.fontp = currinf.fonttable->value(readINT(ch - FNT1 + 1)); if (currinf.fontp == NULL) { errorMsg = i18n("The DVI code referred to a font which was not previously defined."); return; } currinf.set_char_p = currinf.fontp->set_char_p; break; case XXX1: case XXX2: case XXX3: case XXX4: if (is_vfmacro == false) { word_boundary_encountered = true; line_boundary_encountered = true; space_encountered = true; } a = readUINT(ch - XXX1 + 1); if (a > 0) { char *cmd = new char[a+1]; strncpy(cmd, (char *)command_pointer, a); command_pointer += a; cmd[a] = '\0'; applicationDoSpecial(cmd); delete [] cmd; } break; case FNTDEF1: case FNTDEF2: case FNTDEF3: case FNTDEF4: command_pointer += 12 + ch - FNTDEF1 + 1; { quint8 tempa = readUINT8(); quint8 tempb = readUINT8(); command_pointer += tempa + tempb; } break; case PRE: case POST: case POSTPOST: errorMsg = i18n("An illegal command was encountered."); return; break; default: errorMsg = i18n("The unknown op-code %1 was encountered.", ch); return; } /* end switch*/ } /* end else (ch not a SETCHAR or FNTNUM) */ #ifdef DEBUG_RENDER if (currentlyDrawnPage->textBoxList.size() > 0) kDebug(kvs::dvi) << "Element:" << currentlyDrawnPage->textBoxList.last().box << currentlyDrawnPage->textBoxList.last().text << " ? s:" << space_encountered << " / nl:" << line_boundary_encountered << " / w:" << word_boundary_encountered << ", " << last_space_index << "/" << currentlyDrawnPage->textBoxList.size(); #endif /* heuristic to properly detect newlines; a space is needed */ if (after_space && line_boundary_encountered && word_boundary_encountered) { if (currentlyDrawnPage->textBoxList.last().text.endsWith('\n')) currentlyDrawnPage->textBoxList.last().text.chop(1); currentlyDrawnPage->textBoxList.last().text += " \n"; after_space = false; } /* a "space" has been found and there is some (new) character in the array */ if (space_encountered && (currentlyDrawnPage->textBoxList.size() > last_space_index)) { for (int lidx = last_space_index+1; lidx<currentlyDrawnPage->textBoxList.size(); ++lidx) { // merge two adjacent boxes which are part of the same word currentlyDrawnPage->textBoxList[lidx-1].box.setRight(currentlyDrawnPage->textBoxList[lidx].box.x()); } #ifdef DEBUG_RENDER QString lastword(currentlyDrawnPage->textBoxList[last_space_index].text); for (int lidx = last_space_index+1; lidx<currentlyDrawnPage->textBoxList.size(); ++lidx) lastword += currentlyDrawnPage->textBoxList[lidx].text; kDebug(kvs::dvi) << "space encountered: '" << lastword << "'"; #endif last_space_index = currentlyDrawnPage->textBoxList.size(); after_space = true; } } /* end for */ }